package org.opsli.modulars.business.app.web;

import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.business.emergency.EmergencyReportModel;
import org.opsli.api.wrapper.business.fileManage.FileManageModel;
import org.opsli.api.wrapper.business.patrolLocation.PatrolLocationModel;
import org.opsli.api.wrapper.business.patrolRouteRecord.PatrolRouteRecordModel;
import org.opsli.api.wrapper.business.patrolStation.PatrolStationModel;
import org.opsli.api.wrapper.business.patrolStationRecord.PatrolStationRecordModel;
import org.opsli.api.wrapper.business.patrolTask.PatrolTaskModel;
import org.opsli.api.wrapper.business.pipelineLayout.PipelineModel;
import org.opsli.api.wrapper.business.pipelineStation.PipelineStationModel;
import org.opsli.api.wrapper.business.route.RouteModel;
import org.opsli.api.wrapper.business.routeStation.RouteStationModel;
import org.opsli.api.wrapper.business.signRecord.SignRecordModel;
import org.opsli.api.wrapper.business.valveDeviceNow.ValveDeviceNowModel;
import org.opsli.api.wrapper.patrolConfig.PatrolConfigModel;
import org.opsli.api.wrapper.projectRecord.ProjectRecordModel;
import org.opsli.api.wrapper.stationTask.StationTaskModel;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.api.Result;
import org.opsli.core.utils.GpsCoordinateUtils;
import org.opsli.core.utils.JwtUtil;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.business.app.entity.IndustrialUser;
import org.opsli.modulars.business.appUpgrade.service.IAppUpgradeService;
import org.opsli.modulars.business.appVersion.entity.AppProjectVersion;
import org.opsli.modulars.business.appVersion.entity.AppVersion;
import org.opsli.modulars.business.appVersion.service.IAppVersionService;
import org.opsli.modulars.business.czData.entity.CzData;
import org.opsli.modulars.business.czData.service.ICzDataService;
import org.opsli.modulars.business.emergency.entity.EmergencyReport;
import org.opsli.modulars.business.emergency.mapper.EmergencyReportMapper;
import org.opsli.modulars.business.emergency.service.IEmergencyReportService;
import org.opsli.modulars.business.emergencyTask.entity.EmergencyReportTask;
import org.opsli.modulars.business.emergencyTask.entity.EmergencyReportTaskApp;
import org.opsli.modulars.business.emergencyTask.mapper.EmergencyReportTaskMapper;
import org.opsli.modulars.business.emergencyTask.service.IEmergencyReportTaskService;
import org.opsli.modulars.business.equipment.entity.*;
import org.opsli.modulars.business.equipment.service.IEquipmentService;
import org.opsli.modulars.business.fileManage.entity.FileManage;
import org.opsli.modulars.business.fileManage.service.IFileManageService;
import org.opsli.modulars.business.patrolConfig.entity.PatrolConfig;
import org.opsli.modulars.business.patrolConfig.service.IPatrolConfigService;
import org.opsli.modulars.business.patrolLocation.entity.PatrolLocation;
import org.opsli.modulars.business.patrolLocation.service.IPatrolLocationService;
import org.opsli.modulars.business.patrolRouteRecord.entity.PatrolRouteRecord;
import org.opsli.modulars.business.patrolRouteRecord.service.IPatrolRouteRecordService;
import org.opsli.modulars.business.patrolStation.entity.PatrolStation;
import org.opsli.modulars.business.patrolStation.service.IPatrolStationService;
import org.opsli.modulars.business.patrolStationRecord.entity.PatrolStationRecord;
import org.opsli.modulars.business.patrolStationRecord.service.IPatrolStationRecordService;
import org.opsli.modulars.business.patrolTask.entity.PatrolTask;
import org.opsli.modulars.business.patrolTask.mapper.PatrolTaskMapper;
import org.opsli.modulars.business.patrolTask.service.IPatrolTaskService;
import org.opsli.modulars.business.pipelineLayout.entity.Pipeline;
import org.opsli.modulars.business.pipelineLayout.mapper.PipelineMapper;
import org.opsli.modulars.business.pipelineLayout.service.IPipelineService;
import org.opsli.modulars.business.pipelineStation.entity.PipelineStationDp;
import org.opsli.modulars.business.pipelineStation.service.IPipelineStationService;
import org.opsli.modulars.business.pipelineLayout.entity.Pipeline;
import org.opsli.modulars.business.pipelineLayout.service.IPipelineService;
import org.opsli.modulars.business.pipelineStation.entity.PipelineStation;
import org.opsli.modulars.business.pipelineStation.service.IPipelineStationService;
import org.opsli.modulars.business.projectRecord.service.IProjectRecordService;
import org.opsli.modulars.business.projectTask.entity.ProjectTask;
import org.opsli.modulars.business.projectTask.entity.ProjectTaskData;
import org.opsli.modulars.business.projectTask.service.IProjectTaskService;
import org.opsli.modulars.business.projectTask.web.ProjectTaskRestController;
import org.opsli.modulars.business.projectTaskRecord.entity.ProjectTaskRecord;
import org.opsli.modulars.business.projectTaskRecord.service.IProjectTaskRecordService;
import org.opsli.modulars.business.projectTaskRecord.web.ProjectTaskRecordRestController;
import org.opsli.modulars.business.route.entity.Route;
import org.opsli.modulars.business.route.service.IRouteService;
import org.opsli.modulars.business.routeStation.entity.RouteStation;
import org.opsli.modulars.business.routeStation.entity.RouteStationAPP;
import org.opsli.modulars.business.routeStation.entity.RouteStationZJ;
import org.opsli.modulars.business.routeStation.service.IRouteStationService;
import org.opsli.modulars.business.routeStation.service.impl.RouteStationServiceImpl;
import org.opsli.modulars.business.screenConfig.entity.ScreenConfig;
import org.opsli.modulars.business.screenConfig.service.IScreenConfigService;
import org.opsli.modulars.business.signRecord.entity.SignRecord;
import org.opsli.modulars.business.signRecord.service.ISignRecordService;
import org.opsli.modulars.business.stationTask.entity.StationTask;
import org.opsli.modulars.business.stationTask.service.IStationTaskService;
import org.opsli.modulars.business.userRoute.entity.UserRoute;
import org.opsli.modulars.business.userRoute.service.IUserRouteService;
import org.opsli.modulars.business.userStation.entity.UserStation;
import org.opsli.modulars.business.userStation.service.IUserStationService;
import org.opsli.modulars.business.valveDevice.service.IValveDeviceService;
import org.opsli.modulars.business.valveDeviceHis.entity.ValveDeviceHis;
import org.opsli.modulars.business.valveDeviceHis.service.IValveDeviceHisService;
import org.opsli.modulars.business.valveDeviceNow.service.IValveDeviceNowService;
import org.opsli.modulars.business.valveStation.service.IValveStationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Api(tags="app所需接口二类")
@Slf4j
@ApiRestController("/appbusiness/two")
public class AppTwoController {



    @Autowired
    private IPatrolStationRecordService patrolStationRecordService;
    @Autowired
    private IPatrolStationService patrolStationService;
    @Autowired
    private IFileManageService fileManageService;
    @Autowired
    private IEmergencyReportService emergencyReportService;
    @Autowired
    private ISignRecordService signRecordService;
    @Autowired
    private IPatrolRouteRecordService routeRecordService;
    @Autowired
    private IPatrolTaskService taskService;
    @Autowired
    private IUserRouteService userRouteService;
    @Autowired
    private IRouteStationService routeStationService;
    @Autowired
    private IPatrolLocationService locationService;
    @Autowired
    private IRouteService routeService;
    @Autowired
    private IAppVersionService versionService;
    @Autowired
    private IAppUpgradeService upgradeService;
    @Autowired
    private IPatrolConfigService configService;
    @Autowired
    private IStationTaskService stationTaskService;
    @Autowired
    private IUserStationService userStationService;
    @Autowired
    private IValveDeviceNowService valveDeviceService;
    @Autowired
    private IValveDeviceHisService valveDeviceHisService;
    @Autowired
    private IValveStationService valveStationService;
    @Autowired
    private IPipelineService iPipelineService;
    @Autowired
    private IPipelineStationService iPipelineStationService;
    @Autowired
    private IScreenConfigService screenConfigService;
    @Autowired
    private EmergencyReportTaskMapper taskMapper;
    @Autowired
    private IEmergencyReportTaskService emergencyReportTaskService;
    @Autowired
    private EmergencyReportMapper reportMapper;
    @Autowired
    private EmergencyReportTaskMapper emergencyReportTaskMapper;
    @Autowired
    private PatrolTaskMapper patrolTaskMapper;
    @Autowired
    private IProjectRecordService iProjectRecordService;
    @Autowired
    private IProjectTaskService iProjectTaskService;
    @Autowired
    private IProjectTaskRecordService iProjectTaskRecordService;
    @Autowired
    private ProjectTaskRecordRestController projectTaskRecordRestController;
    @Autowired
    private ProjectTaskRestController projectTaskRestController;

    @Autowired
    private ICzDataService czDataService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private IEquipmentService equipmentService;

    @Value("${opsli.fileUrl}")
    private  String fileUrl;
    @Value("${opsli.filePath}")
    private  String filePath;

    public static final String PREFIX_ROUTEID_PATH = "opsli:eden:routeId:path:";

    private Logger log =  LoggerFactory.getLogger("sj");

    @GetMapping(value = "/test")
    @Transactional(readOnly = false)
    public void test(){
        /*List<CmdValveConfigSend> list=equipmentService.selectCmdValve("148");
        System.out.println(JSON.toJSONString(list));*/
         /*ValveMonitorData data=new ValveMonitorData();
        data.setApn("123");
        data.setDeviceId("588744");
        data.setIp("110.254.123.46");
        data.setCreateTime(new Date());
        equipmentService.insertValveMonitorData(data);*/
       /* GatewayMonitorData data=equipmentService.getGatewayMonitorData("588744");
        System.out.println(JSON.toJSONString(data));*/
        GatewayMonitorData data=new GatewayMonitorData();
        data.setApn("z234");
        data.setId(13L);
        data.setUpdateTime(ZkUtils.getDateStr());
        equipmentService.updateGatewayMonitorData(data);
        System.out.println("123");
    }


    @GetMapping(value = "/upgrade")
    public Result<Map> upgrade(HttpServletRequest request, @RequestParam(name="appid") String appid, @RequestParam(name="version") String version,@RequestParam(name="imei") String imei) throws Exception{

        System.out.println("appid="+appid+",version="+version+",imei="+imei);
        Result<Map> result=new Result<Map>();
        AppVersion appVersion=versionService.findLast();
        Map map=new HashMap();
        map.put("version",appVersion.getAppVersion());
        map.put("note",appVersion.getNote());
        map.put("url",appVersion.getUrl());
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }

    @GetMapping(value = "/upgradeProject")
    public Result<Map> upgradeProject(HttpServletRequest request, @RequestParam(name="appid") String appid, @RequestParam(name="version") String version,@RequestParam(name="imei") String imei) throws Exception{

        System.out.println("appid="+appid+",version="+version+",imei="+imei);
        Result<Map> result=new Result<Map>();
        AppProjectVersion appVersion=versionService.findLastProject();
        Map map=new HashMap();
        map.put("version",appVersion.getAppVersion());
        map.put("note",appVersion.getNote());
        map.put("url",appVersion.getUrl());
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }


    @GetMapping(value = "/getUserInfo")
    public Result<Map> getUserInfo(HttpServletRequest request) throws Exception{
        String username = JwtUtil.getUserNameByToken(request);
        Result<Map> result=new Result<Map>();
        UserModel user = UserUtil.getAppUser(username);
        Map map=new HashMap();
        map.put("sign",user.getIsInspector());
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }

    //获取支阀井列表
    @GetMapping(value = "/getZfjList")
    public List<Map> getZfjList(HttpServletRequest request,String controlAreaText,String devid) throws Exception{
        List<PatrolStationModel> list=patrolStationService.findListByControlAreaText(devid,"2",controlAreaText);
        List<Map> maps=new ArrayList<Map>();
        for(PatrolStationModel model:list){
            Map map=new HashMap();
            map.put("name",model.getStationName());
            map.put("area",model.getControlAreaText());
            map.put("id",model.getId());
            if(ZkUtils.isNotBlank(model.getControlAreaText())){
                maps.add(map);
            }
        }
        return maps;
    }

    @GetMapping(value = "/getSerachZfj")
    public List<Map> getSerachZfj(HttpServletRequest request,String stationName,String devid) throws Exception{
        List<PatrolStationModel> list=patrolStationService.findListByTypeAndName(devid,"2",stationName);
        List<Map> maps=new ArrayList<Map>();
        for(PatrolStationModel model:list){
            Map map=new HashMap();
            map.put("name",model.getStationName());
            map.put("id",model.getId());
            maps.add(map);
        }
        return maps;
    }

    /**
     * 大屏支阀门井 控制区域模糊查询
     * @param request
     * @param controlAreaText
     * @param devid
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/getSerachZfjKZ")
    public List<Map> getSerachZfjKZ(HttpServletRequest request,String controlAreaText,String devid) throws Exception{

        List<PatrolStationModel> list=patrolStationService.findListByTypeAndName(devid,"2",controlAreaText);
        List<Map> maps=new ArrayList<Map>();
        for(PatrolStationModel model:list){
            Map map=new HashMap();
            map.put("name",model.getStationName());
            map.put("area",model.getControlAreaText());
            maps.add(map);
        }
        return maps;
    }

    @GetMapping(value = "/getSerachFj")
    public List<Map> getSerachFj(HttpServletRequest request,String stationName,String devid) throws Exception{
        List<PatrolStationModel> list=patrolStationService.findListByTypeAndName(devid,"1",stationName);
        List<Map> maps=new ArrayList<Map>();
        for(PatrolStationModel model:list){
            Map map=new HashMap();
            map.put("name",model.getStationName());
            map.put("id",model.getId());
            maps.add(map);
        }
        return maps;
    }


    //搜索栏查询调压柜
    @GetMapping(value = "/getSerachTyg")
    public List<Map> getSerachTyg(HttpServletRequest request,String stationName,String devid) throws Exception{
        List<PatrolStationModel> list=patrolStationService.findListByTypeAndName(devid,"3",stationName);
        List<Map> maps=new ArrayList<Map>();
        for(PatrolStationModel model:list){
            Map map=new HashMap();
            map.put("name",model.getStationName());
            map.put("id",model.getId());
            maps.add(map);
        }
        return maps;
    }

    @GetMapping(value = "/getSerachZfjDetail")
    public Map getSerachZfjDetail(HttpServletRequest request,String id,String devid) throws Exception{
        Map map=new HashMap();
        PatrolStationModel model=patrolStationService.get(id);
        map.put("name",model.getStationName());
        map.put("id",model.getId());
        map.put("type","121");
        if(ZkUtils.isNotBlank(model.getLongitude())) {
            MapCordinatesVo cordinatesVo = new MapCordinatesVo();
            cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
            cordinatesVo.setLat(new BigDecimal(model.getDimension()));
            cordinatesVo = CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
            map.put("ln", cordinatesVo.getLon());
            map.put("lt", cordinatesVo.getLat());
            map.put("location", model.getLocation());
            map.put("userName", model.getUserName());
            map.put("lastTime", model.getLastTime());
            map.put("pic", fileUrl+model.getLastPic());
            map.put("video", fileUrl+model.getLastVideo());
        }
        return map;
    }



    @GetMapping(value = "/dpFStation")
    public List<Map> dpFStation(HttpServletRequest request,String devid) throws Exception{
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        List<PatrolStationModel> models =patrolStationService.findListByType(devid,"2");
        if(models!=null&&models.size()>0){
            for(PatrolStationModel model:models){
                Map map=new HashMap();
                map.put("name",model.getStationName());
                map.put("id",model.getId());
                map.put("type","121");
                if(ZkUtils.isNotBlank(model.getLongitude())) {
                    MapCordinatesVo cordinatesVo = new MapCordinatesVo();
                    cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
                    cordinatesVo.setLat(new BigDecimal(model.getDimension()));
                    cordinatesVo = CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                    map.put("ln", cordinatesVo.getLon());
                    map.put("lt", cordinatesVo.getLat());
                    map.put("location", model.getLocation());
                    map.put("userName", model.getUserName());
                    map.put("lastTime", model.getLastTime());
                    List<Map> mapList=new ArrayList();
                    if(null != model.getAreaType()){
                        if(model.getAreaType().equals("1")) {
                            Map map1 = new HashMap();
                            String text= model.getControlArea();
                            JSONObject stuInfoObj = JSONObject.parseObject(text);
                            String center = stuInfoObj.getString("center");
                            String radius = stuInfoObj.getString("radius");
                            JSONObject lnglatJson = JSONObject.parseObject(center);
                            String lt = lnglatJson.getString("lng");
                            String ln = lnglatJson.getString("lat");
                            map1.put("lt",lt);
                            map1.put("ln",ln);
                            map1.put("radius",radius);
                            mapList.add(map1);
                            System.out.println(lt + "---" + ln+"-------"+radius);
                        }else if(model.getAreaType().equals("2")){
                            mapList= JSON.parseArray(model.getControlArea(), Map.class);
                            mapList.remove(mapList.size()-1);
                            for(Map map1:mapList){
                                String latLng =map1.get("latLng").toString();
                                JSONObject stuInfoObj = JSONObject.parseObject(latLng);//先转换成JSONObject类型
                                String lt= stuInfoObj.getString("lng");
                                String ln= stuInfoObj.getString("lat");
                                System.out.println(lt+"---"+ln);
                                map1.put("lt",lt);
                                map1.put("ln",ln);
                            }
                        }else if(model.getAreaType().equals("3")){

                            mapList= JSON.parseArray(model.getControlArea(), Map.class);
                            mapList.remove(mapList.size()-1);
                            for(Map map1:mapList){
                                String latLng =map1.get("latLng").toString();
                                JSONObject stuInfoObj = JSONObject.parseObject(latLng);//先转换成JSONObject类型
                                String lt= stuInfoObj.getString("lng");
                                String ln= stuInfoObj.getString("lat");
                                System.out.println(lt+"---"+ln);
                                map1.put("lt",lt);
                                map1.put("ln",ln);
                            }
                        }
                    }
                    map.put("controlArea",mapList);//管控区域
                    map.put("areaType",model.getAreaType());//管控区域类型
                    list.add(map);
                }
            }
        }
        return list;
    }
    @GetMapping(value = "/getEaerId")
    public  List<Map> getEaerId(HttpServletRequest request,String id) throws Exception{

        List<Map> list=new ArrayList<Map>();
        List<PatrolStationModel> models =patrolStationService.findListQu(id);
        if(models!=null&&models.size()>0){
            for(PatrolStationModel model:models){
                Map map=new HashMap();
                    List<Map> mapList=new ArrayList();
                    if(null != model.getAreaType()){
                        if(model.getAreaType().equals("1")) {
                            Map map1 = new HashMap();
                            String text= model.getControlArea();
                            JSONObject stuInfoObj = JSONObject.parseObject(text);
                            String center = stuInfoObj.getString("center");
                            String radius = stuInfoObj.getString("radius");
                            JSONObject lnglatJson = JSONObject.parseObject(center);
                            String lt = lnglatJson.getString("lng");
                            String ln = lnglatJson.getString("lat");
                            map1.put("lt",lt);
                            map1.put("ln",ln);
                            map1.put("radius",radius);
                            mapList.add(map1);
                            System.out.println(lt + "---" + ln+"-------"+radius);
                        }else if(model.getAreaType().equals("2")){
                            mapList= JSON.parseArray(model.getControlArea(), Map.class);
                            mapList.remove(mapList.size()-1);
                            for(Map map1:mapList){
                                String latLng =map1.get("latLng").toString();
                                JSONObject stuInfoObj = JSONObject.parseObject(latLng);//先转换成JSONObject类型
                                String lt= stuInfoObj.getString("lng");
                                String ln= stuInfoObj.getString("lat");
                                System.out.println(lt+"---"+ln);
                                map1.put("lt",lt);
                                map1.put("ln",ln);
                            }
                        }else if(model.getAreaType().equals("3")){

                            mapList= JSON.parseArray(model.getControlArea(), Map.class);
                            mapList.remove(mapList.size()-1);
                            for(Map map1:mapList){
                                String latLng =map1.get("latLng").toString();
                                JSONObject stuInfoObj = JSONObject.parseObject(latLng);//先转换成JSONObject类型
                                String lt= stuInfoObj.getString("lng");
                                String ln= stuInfoObj.getString("lat");
                                System.out.println(lt+"---"+ln);
                                map1.put("lt",lt);
                                map1.put("ln",ln);
                            }
                        }
                    }
                    map.put("controlArea",mapList);//管控区域
                    map.put("areaType",model.getAreaType());//管控区域类型
                    list.add(map);
                }
            }

        return list;
    }

    @GetMapping(value = "/getLocation")
    public List<Map> getLocation(HttpServletRequest request,String devid) throws Exception{
        List<PatrolLocationModel> list=patrolStationService.findPList(devid);
        List<Map> maps=new ArrayList<Map>();
        for(PatrolLocationModel model:list){
            Map map=new HashMap();
            map.put("name",model.getUserName());
            map.put("location",model.getLocation().replace("河南省郑州市",""));
            map.put("state","在线");
            map.put("userId",model.getUserId());
            maps.add(map);
        }
        return maps;
    }

    @GetMapping(value = "/getBJONE")
    public List<Map> getBJONE(HttpServletRequest request,String devid) throws Exception{
        List<ValveDeviceHis> list=valveDeviceHisService.sList(devid);
        List<Map> maps=new ArrayList<Map>();
        for(ValveDeviceHis model:list){
            Map map=new HashMap();
            String name=valveStationService.get(model.getValveId()).getStationName();
            map.put("name",name);
            map.put("nd",model.getPotency());
            map.put("bit2",model.getBit2());
            map.put("bit3",model.getBit3());
            map.put("bit1",model.getBit1());
            map.put("time",model.getLastTime());
            maps.add(map);
        }
        return maps;
    }

    /**
     * 工业用户
     * @param request
     * @param devid
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/dpIndustrial")
    public List<IndustrialUser> dpIndustrial(HttpServletRequest request, String devid) throws Exception{

        List<IndustrialUser> list=new ArrayList<IndustrialUser>();
        list.add(new IndustrialUser());
        List<Map> data =HttpRequest2.getYc();

        if(data!=null){
            for (IndustrialUser user:list){
                List<Map> mapList=new ArrayList<>();

                user.setIndustrialUser("金驹铝业");//工业用户名称
                user.setLongitude("113.242104");//经度
                user.setLatitude("34.734493");//维度

                for(Map map:data){

                    Map m=new HashMap();
                    String data1=map.get("采集点名称").toString();
                    String data2=map.get("压力").toString();
                    String data3=map.get("流量").toString();
                    String data4=map.get("总量").toString();
                    System.out.println(data1+" "+data2+" "+data3+" "+data4);

                    if("金驹铝业-北流量计".equals(data1)){
                        //采集点名称
                        m.put("data1",data1);
                        //压力
                        m.put("data2",new BigDecimal(data2).setScale(2,BigDecimal.ROUND_UP));
                        //流量
                        m.put("data3",new BigDecimal(data3).setScale(2,BigDecimal.ROUND_UP));
                        //流量
                        m.put("data4",new BigDecimal(data4).setScale(2,BigDecimal.ROUND_UP));

                        mapList.add(m);

                    } else if("金驹铝业-南流量计(主)".equals(data1)){
                        //采集点名称
                        m.put("data1",data1);
                        //压力
                        m.put("data2",new BigDecimal(data2).setScale(2,BigDecimal.ROUND_UP));
                        //流量
                        m.put("data3",new BigDecimal(data3).setScale(2,BigDecimal.ROUND_UP));
                        //流量
                        m.put("data4",new BigDecimal(data4).setScale(2,BigDecimal.ROUND_UP));

                        mapList.add(m);
                    }

                }

                user.setMeterList(mapList);

            }

        }
        return list;
    }

    @GetMapping(value = "/getCz")
    public List<CzData> getCz(HttpServletRequest request,String devid) throws Exception{

        List<CzData>  czDataList=czDataService.getDataList();
        for(CzData czData:czDataList){
            BigDecimal bg = new BigDecimal(czData.getPt101());
            czData.setPt101(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getPt102());
            czData.setPt102(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getPt103());
            czData.setPt103(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");

            bg = new BigDecimal(czData.getTt101());
            czData.setTt101(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getTt102());
            czData.setTt102(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getTt103());
            czData.setTt103(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getTt104());
            czData.setTt104(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getTt105());
            czData.setTt105(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");


            bg = new BigDecimal(czData.getFt101Gk());
            czData.setFt101Gk(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getFt101Bk());
            czData.setFt101Bk(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getFt101Pt());
            czData.setFt101Pt(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getFt101Tt());
            czData.setFt101Tt(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");


            bg = new BigDecimal(czData.getFt102Gk());
            czData.setFt102Gk(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getFt102Bk());
            czData.setFt102Bk(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getFt102Pt());
            czData.setFt102Pt(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getFt102Tt());
            czData.setFt102Tt(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");

            bg = new BigDecimal(czData.getFt103Gk());
            czData.setFt103Gk(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getFt103Bk());
            czData.setFt103Bk(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getFt103Pt());
            czData.setFt103Pt(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");
            bg = new BigDecimal(czData.getFt103Tt());
            czData.setFt103Tt(bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"");

        }

        return czDataList;

    }

    @GetMapping(value = "/getGy")
    public List<Map> getGy(HttpServletRequest request,String devid) throws Exception{

        List<Map> maps=new ArrayList<Map>();
        List<Map> list=new ArrayList<Map>();
        List<Map> data=new ArrayList<Map>();
        if(devid.equals("41001")){
            data=HttpRequest2.getYc();
            if(data!=null){
                for(Map map:data){
                    Map m=new HashMap();
                    String data1=map.get("采集点名称").toString();
                    String data2=map.get("压力").toString();
                    String data3=map.get("流量").toString();
                    String data4=map.get("总量").toString();
                    System.out.println(data1+" "+data2+" "+data3+" "+data4);

                    //采集点名称
                    m.put("data1",data1);
                    //压力
                    m.put("data2",new BigDecimal(data2).setScale(2,BigDecimal.ROUND_UP));
                    //流量
                    m.put("data3",new BigDecimal(data3).setScale(2,BigDecimal.ROUND_UP));
                    //流量
                    m.put("data4",new BigDecimal(data4).setScale(2,BigDecimal.ROUND_UP));
                    list.add(m);

                }

            }

        }else{
            for(int i=0;i<20;i++){
                if(i==0){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","苍南罗茨50表");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }else  if(i==1){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","苍南涡轮80表");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }else  if(i==2){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","浠水一中");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }else  if(i==3){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","福尔嘉医药化工有限公司");
                    //压力
                    m.put("data2","117.14");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","2088414.27");
                    list.add(m);
                }else  if(i==4){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","晨科饲料厂");
                    //压力
                    m.put("data2","138.32");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","1004372.38");
                    list.add(m);
                }else  if(i==5){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","高科铝业");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }else  if(i==6){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","关口砖厂");
                    //压力
                    m.put("data2","111.20");
                    //流量
                    m.put("data3","297.25");
                    //累计气量
                    m.put("data4","1532723.19");
                    list.add(m);
                }else  if(i==7){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","京华陶瓷");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }else  if(i==8){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","瑞林特铝厂");
                    //压力
                    m.put("data2","146.36");
                    //流量
                    m.put("data3","15.60");
                    //累计气量
                    m.put("data4","470346.45");
                    list.add(m);
                }else  if(i==9){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","赛尔");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }else  if(i==10){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","装贞");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }else  if(i==11){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","洗涤厂");
                    //压力
                    m.put("data2","106.79");
                    //流量
                    m.put("data3","78.72");
                    //累计气量
                    m.put("data4","643207.24");
                    list.add(m);
                }else  if(i==12){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","老磨坊");
                    //压力
                    m.put("data2","113.06");
                    //流量
                    m.put("data3","136.44");
                    //累计气量
                    m.put("data4","930669.17");
                    list.add(m);
                }else  if(i==13){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","丁斯垱砖厂");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }else  if(i==14){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","浠水思源学校");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }else  if(i==15){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","赛典装饰");
                    //压力
                    m.put("data2","110.71");
                    //流量
                    m.put("data3","50.81");
                    //累计气量
                    m.put("data4","752510.29");
                    list.add(m);
                }else  if(i==16){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","海大");
                    //压力
                    m.put("data2","151.36");
                    //流量
                    m.put("data3","9.87");
                    //累计气量
                    m.put("data4","731189.00");
                    list.add(m);
                }else  if(i==17){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","人民医院上");
                    //压力
                    m.put("data2","116.11");
                    //流量
                    m.put("data3","108.20");
                    //累计气量
                    m.put("data4","1781964.21");
                    list.add(m);
                }else  if(i==18){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","人民医院下");
                    //压力
                    m.put("data2","116.81");
                    //流量
                    m.put("data3","93.03");
                    //累计气量
                    m.put("data4","1160772.55");
                    list.add(m);
                }else  if(i==19){
                    Map m=new HashMap();

                    //采集点名称
                    m.put("data1","鑫成饲料");
                    //压力
                    m.put("data2","0");
                    //流量
                    m.put("data3","0");
                    //累计气量
                    m.put("data4","0");
                    list.add(m);
                }
            }
        }

        String s="[{\"data4\":\"4031942.0\",\"data3\":\"356.17\",\"data2\":\"204.9\",\"data1\":\"合力铜业-东侧流量计(主)\"},{\"data4\":\"4430027.68\",\"data3\":\"0.0\",\"data2\":\"221.84\",\"data1\":\"合力铜业-西侧流量计\"},{\"data4\":\"32527182.17\",\"data3\":\"0.0\",\"data2\":\"91.18\",\"data1\":\"金驹铝业-北流量计\"},{\"data4\":\"22911899.13\",\"data3\":\"1798.84\",\"data2\":\"371.73\",\"data1\":\"金驹铝业-南流量计(主)\"},{\"data4\":\"3404558.27\",\"data3\":\"89.88\",\"data2\":\"199.17\",\"data1\":\"亨达东表-主\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"亨达西表-副\"},{\"data4\":\"53.68\",\"data3\":\"0.0\",\"data2\":\"100.89\",\"data1\":\"星火铝业北-副\"},{\"data4\":\"3022712.22\",\"data3\":\"123.27\",\"data2\":\"171.17\",\"data1\":\"星火铝业南-主\"},{\"data4\":\"645201.74\",\"data3\":\"0.0\",\"data2\":\"428.8\",\"data1\":\"景文百货北表\"},{\"data4\":\"52198.09\",\"data3\":\"0.0\",\"data2\":\"99.93\",\"data1\":\"景文百货南表\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"雅乐轩东\"},{\"data4\":\"1301648.06\",\"data3\":\"24.97\",\"data2\":\"109.66\",\"data1\":\"雅乐轩西\"},{\"data4\":\"197600.0\",\"data3\":\"0.0\",\"data2\":\"100.38\",\"data1\":\"铁路技校\"},{\"data4\":\"3849392.0\",\"data3\":\"0.0\",\"data2\":\"305.16\",\"data1\":\"铝都新材料\"},{\"data4\":\"25126.62\",\"data3\":\"0.0\",\"data2\":\"115.3\",\"data1\":\"龙溪湾东表\"},{\"data4\":\"348275.64\",\"data3\":\"0.0\",\"data2\":\"109.72\",\"data1\":\"龙溪湾西表\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"金星助剂\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"利丰化工\"},{\"data4\":\"16052.05\",\"data3\":\"0.0\",\"data2\":\"118.21\",\"data1\":\"鑫鑫铝业东表\"},{\"data4\":\"9778380.11\",\"data3\":\"562.25\",\"data2\":\"122.27\",\"data1\":\"鑫鑫铝业西表\"},{\"data4\":\"2757862.15\",\"data3\":\"0.0\",\"data2\":\"99.92\",\"data1\":\"天马西表 苍南\"},{\"data4\":\"5267207.14\",\"data3\":\"179.34\",\"data2\":\"112.68\",\"data1\":\"天马东表 苍南\"},{\"data4\":\"3574871.0\",\"data3\":\"364.12\",\"data2\":\"154.51\",\"data1\":\"天马新厂 天信卡表\"},{\"data4\":\"7347267.54\",\"data3\":\"501.58\",\"data2\":\"187.4\",\"data1\":\"孵化园 天信\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"海塞科技 天信\"},{\"data4\":\"16582.0\",\"data3\":\"0.0\",\"data2\":\"96.98\",\"data1\":\"彩美汇 东表 天信fcm\"},{\"data4\":\"2654526.0\",\"data3\":\"0.0\",\"data2\":\"111.65\",\"data1\":\"彩美汇西表天信tbqz\"},{\"data4\":\"1285802.9\",\"data3\":\"44.87\",\"data2\":\"120.43\",\"data1\":\"长城分子筛南\"},{\"data4\":\"49.57\",\"data3\":\"0.0\",\"data2\":\"99.74\",\"data1\":\"长城分子筛北\"},{\"data4\":\"888808.41\",\"data3\":\"0.0\",\"data2\":\"113.89\",\"data1\":\"宇超机械\"},{\"data4\":\"397563.0\",\"data3\":\"0.0\",\"data2\":\"100.88\",\"data1\":\"龙丰农业机械\"},{\"data4\":\"2262579.12\",\"data3\":\"0.0\",\"data2\":\"113.09\",\"data1\":\"雪山实业\"},{\"data4\":\"1612731.0\",\"data3\":\"0.0\",\"data2\":\"427.42\",\"data1\":\"商都建设\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"正航实业东表\"},{\"data4\":\"1141582.0\",\"data3\":\"0.0\",\"data2\":\"110.31\",\"data1\":\"中海威 东表\"},{\"data4\":\"35.0\",\"data3\":\"0.0\",\"data2\":\"93.24\",\"data1\":\"中海威 西表\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"天信 南表\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"天信 北表\"},{\"data4\":\"1600476.51\",\"data3\":\"0.0\",\"data2\":\"98.84\",\"data1\":\"苍南 北表\"},{\"data4\":\"64.67\",\"data3\":\"0.0\",\"data2\":\"99.62\",\"data1\":\"苍南 南表\"},{\"data4\":\"29763.0\",\"data3\":\"2.16\",\"data2\":\"103.57\",\"data1\":\"昌煜实业\"},{\"data4\":\"215778.4\",\"data3\":\"0.0\",\"data2\":\"111.4\",\"data1\":\"佳美和\"},{\"data4\":\"1295215.0\",\"data3\":\"0.0\",\"data2\":\"111.82\",\"data1\":\"华祥耐材\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"天信流量计北路\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"苍南流量计\"},{\"data4\":\"3665441.86\",\"data3\":\"824.32\",\"data2\":\"121.91\",\"data1\":\"苍南流量计\"},{\"data4\":\"9026015.03\",\"data3\":\"0.0\",\"data2\":\"102.71\",\"data1\":\"苍南流量计\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"天信流量计\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"天信流量计\"},{\"data4\":\"--\",\"data3\":\"--\",\"data2\":\"--\",\"data1\":\"天信流量计北路\"}]";
       /* maps= JSONObject.parseArray(s, Map.class);
        for(Map map:maps){
            if(!map.get("data2").equals("--")){
                list.add(map);
            }
        }*/
        return list;
    }

    @GetMapping(value = "/getTotal")
    public Map getTotal(HttpServletRequest request,String devid) throws Exception{
        Map map=new HashMap();
        List<Pipeline> list=iPipelineService.findList(devid,"2");
        BigDecimal length=new BigDecimal("0");
        if(list!=null&&list.size()>0){
             for(Pipeline p:list) {
                 //中压长度
                 if (ZkUtils.isNotBlank(p.getLength())){
                     BigDecimal a1=new BigDecimal(p.getLength());
                    length=length.add(a1);

                 }
             }
            map.put("len",length.divide(new BigDecimal("1000")).setScale(2, BigDecimal.ROUND_UP));
        }else{
            map.put("len",0);
        }

        return map;
    }


    @GetMapping(value = "/getGasTotal")
    public Map getGasTotal(HttpServletRequest request,String devid) throws Exception{
        Map map=new HashMap();
        CzData data1=czDataService.getToday();
        CzData data2=czDataService.getYesterDay(getFormatDate());
        if(data1!=null&data2!=null){
               BigDecimal a1=new BigDecimal(data1.getFt101Bksum());
               BigDecimal a2=new BigDecimal(data1.getFt102Bksum());
               BigDecimal a3=new BigDecimal(data1.getFt103Bksum());

            BigDecimal a4=new BigDecimal(data2.getFt101Bksum());
            BigDecimal a5=new BigDecimal(data2.getFt102Bksum());
            BigDecimal a6=new BigDecimal(data2.getFt103Bksum());


            map.put("gas",a1.add(a2).add(a3).subtract(a4).subtract(a5).subtract(a6));
        }else{
            map.put("gas",0);
        }

        return map;
    }

    private static String getFormatDate() throws Exception{
        String updated="";
        GregorianCalendar ca = new GregorianCalendar();
        int hour = ca.get(Calendar.HOUR_OF_DAY);
        if(hour<8){
            updated="昨天 08:00";
        }else{
            updated="今天 08:00";
        }
        if (updated.substring(0, 2).equals("今天")){
            String partOfDate = updated.substring(3);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            SimpleDateFormat todaySdf = new SimpleDateFormat("yyyy-MM-dd");
            String today = todaySdf.format(calendar.getTime());
            String finalString = today + " " + partOfDate;
                        /* SimpleDateFormat finalSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                        return finalSdf.parse(finalString);*/
            return finalString;
        }else if (updated.substring(0,2).equals("昨天")){
            String partOfDate = updated.substring(3);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.add(Calendar.DATE, -1);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            SimpleDateFormat yesterdaySdf = new SimpleDateFormat("yyyy-MM-dd");
            String yesterday = yesterdaySdf.format(calendar.getTime());
            String finalString = yesterday + " " + partOfDate;
                        /* SimpleDateFormat finalSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                         return finalSdf.parse(finalString);*/
            return finalString;
        }else {
            /* SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");*/
            return ZkUtils.getDateStr();
        }
    }

    @GetMapping(value = "/getFmSum")
    public Map getFmSum(HttpServletRequest request,String devid) throws Exception{
        Map map=new HashMap();
        map.put("sum1",patrolStationService.getSum(devid,"1"));
        map.put("sum2",patrolStationService.getSum(devid,"2"));
        return map;
    }

    @GetMapping(value = "/getTj")
    public Map getTj(HttpServletRequest request,String devid) throws Exception{
        Map map=new HashMap();
        Integer sum1=patrolStationRecordService.getTodayCount(devid);
        map.put("sum1",sum1);
        return map;
    }

    @GetMapping(value = "/getTySum")
    public Map getTySum(HttpServletRequest request,String devid) throws Exception{
        Map map=new HashMap();
        map.put("sum1",patrolStationService.getSum(devid,"3"));
        map.put("sum2",patrolStationService.getSum(devid,"4"));
        return map;
    }

    @GetMapping(value = "/getScreenConfig")
    public Map getScreenConfig(HttpServletRequest request,String devid) throws Exception{
        Map map=new HashMap();
        ScreenConfig dict=screenConfigService.findLast(devid);
        map.put("id",dict.getId());
        map.put("permisson1",dict.getPermisson1());
        map.put("permisson2",dict.getPermisson2());
        map.put("permisson3",dict.getPermisson3());
        map.put("permisson4",dict.getPermisson4());
        map.put("permisson5",dict.getPermisson5());
        map.put("permisson6",dict.getPermisson6());
        map.put("permisson7",dict.getPermisson7());
        map.put("permisson8",dict.getPermisson8());
        map.put("permisson9",dict.getPermisson9());
        map.put("permisson10",dict.getPermisson10());
        map.put("permisson11",dict.getPermisson11());
        map.put("permisson12",dict.getPermisson12());
        map.put("permisson13",dict.getPermisson13());
        map.put("permisson14",dict.getPermisson14());
        map.put("permisson15",dict.getPermisson15());
        map.put("permisson16",dict.getPermisson16());
        return map;
    }

    @GetMapping(value = "/getBJTWO")
    public List<Map> getBJTWO(HttpServletRequest request,String devid) throws Exception{
        List<ValveDeviceNowModel>list=valveDeviceService.getList(devid);
        List<Map> maps=new ArrayList<Map>();
        for(ValveDeviceNowModel model:list){
            Map map=new HashMap();
            String name=valveStationService.get(model.getValveId()).getStationName();
            map.put("name",name);
            map.put("nd",model.getPotency());
            map.put("bit6",model.getBit6());//移动
            map.put("bit2",model.getBit2());//水位
            map.put("bit3",model.getBit3());//门开
            maps.add(map);
        }
        return maps;
    }

    @GetMapping(value = "/getEmergency")
    public List<Map> getEmergency(HttpServletRequest request,String devid) throws Exception{
        List<EmergencyReportModel> list=emergencyReportService.findListAll(devid);
        List<Map> maps=new ArrayList<Map>();
        for(EmergencyReportModel model:list){
            Map map=new HashMap();
            //标题
            map.put("data1",model.getEmergencyTitle());
            //上报人
            map.put("data2",model.getUserName());
            //时间
            map.put("data3",model.getReportTime().substring(0,10));

            maps.add(map);
        }
        return maps;
    }


    //高压管道
    @GetMapping(value = "/getGyGd")
    public List<Map> getGyGd(HttpServletRequest request,String devid) throws Exception{
        List<Pipeline>list=iPipelineService.findList(devid,"3");
        List<Map> maps=new ArrayList<Map>();
        for(Pipeline model:list){
            Map map=new HashMap();
            //起点
            map.put("data1",model.getOrigin());
            //终点
            map.put("data2",model.getDestination());
            //压力
            map.put("data3",model.getOperatingPressure());
            //规格型号
            map.put("data4",model.getSpecificationModel());
            //材质
            map.put("data5",model.getPipingMaterial());
            //长度
            map.put("data6",model.getLength());
            //id
            map.put("id",model.getId());
            maps.add(map);
        }
        return maps;
    }

    //中压管道Z
    @GetMapping(value = "/getZyGd")
    public List<Map> getZyGd(HttpServletRequest request,String devid) throws Exception{
        List<Pipeline>list=iPipelineService.findList(devid,"2");
        List<Map> maps=new ArrayList<Map>();
        for(Pipeline model:list){
            Map map=new HashMap();
            //起点
            map.put("data1",model.getOrigin());
            //终点
            map.put("data2",model.getDestination());
            //压力
            map.put("data3",model.getOperatingPressure());
            //规格型号
            map.put("data4",model.getSpecificationModel());
            //材质
            map.put("data5",model.getPipingMaterial());
            //长度
            map.put("data6",model.getLength());
            //id
            map.put("id",model.getId());
            maps.add(map);
        }
        return maps;
    }

    //获取管道详情
    @GetMapping(value = "/getGdDetail")
    public List<Map> getGdDetail(HttpServletRequest request,String id) throws Exception{
        /*List<Map> maps=new ArrayList<Map>();
        PipelineModel pipeline=iPipelineService.get(id);
        List<PipelineStation> list=iPipelineStationService.findList(id);
        for(PipelineStation model:list){
            Map map=new HashMap();
            MapCordinatesVo cordinatesVo = new MapCordinatesVo();
            cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
            cordinatesVo.setLat(new BigDecimal(model.getDimension()));
            cordinatesVo = CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
            map.put("ln", cordinatesVo.getLon());
            map.put("lt", cordinatesVo.getLat());
            //起点
            map.put("data1",model.getOrigin());
            //终点
            map.put("data2",model.getDestination());
            //压力
            map.put("data3",model.getOperatingPressure());
            //规格型号
            map.put("data4",model.getSpecificationModel());
            //材质
            map.put("data5",model.getPipingMaterial());
            //长度
            map.put("data6",model.getLength());
            //id
            map.put("id",model.getId());
            maps.add(map);
        }
        return maps;*/
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        List<PipelineModel> models =new ArrayList<PipelineModel>();
        models.add(iPipelineService.get(id));
        if(models!=null&&models.size()>0){
            for(PipelineModel model:models){
                Map map=new HashMap();
                map.put("id",model.getId());
                map.put("name",model.getPipelineRoadAme());
                map.put("specificationModel",model.getSpecificationModel());//规格型号
                map.put("pipingMaterial",model.getPipingMaterial());//管道材质
                map.put("anticorrosionMaterial",model.getAnticorrosionMaterial());//防腐材质
                map.put("length",model.getLength());//长度
                map.put("operatingPressure",model.getOperatingPressure());//运行压力
                List<PipelineStationDp> stationList=iPipelineStationService.findListDp(model.getId());

                if(stationList!=null&&stationList.size()>0) {

                    PipelineStationDp p1=stationList.get(0);//第一条
                    PipelineStationDp p2=stationList.get(stationList.size()-1);//最后一条.
                    p1.setTheFinal("1");
                    p1.setStarting(model.getOrigin());//起点名称
                    p2.setTheFinal("2");
                    p2.setFinish(model.getDestination());//终点名称

                    for(PipelineStationDp station:stationList){
                        MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                        cordinatesVo.setLon(new BigDecimal(station.getLongitude()));
                        cordinatesVo.setLat(new BigDecimal(station.getDimension()));
                        cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                        station.setLongitude(cordinatesVo.getLon().toString());
                        station.setDimension(cordinatesVo.getLat().toString());
                    }

                    map.put("line",model);
                    map.put("value",stationList);
                    map.put("type",1);
                    list.add(map);
                }
            }
        }
        return list;
    }


    //本周事项
    @GetMapping(value = "/getWeek")
    public List<Map> getWeek(HttpServletRequest request,String devid) throws Exception{
        List<PatrolRouteRecord> list1=routeRecordService.getWeekList(devid);
        List<PatrolStationRecord> list2=patrolStationRecordService.getWeekList(devid);
        List<EmergencyReport> list3=emergencyReportService.getWeekList(devid);
        List<ValveDeviceHis> list4=valveDeviceHisService.getWeekList(devid);
        List<Map> maps=new ArrayList<Map>();
        for(PatrolRouteRecord model:list1){
            Map map=new HashMap();
            RouteModel m=routeService.get(model.getRouteId());
            //类别名称
            map.put("name","巡线任务");
            map.put("des",m.getRouteName());
            //类型
            map.put("type",1);
            //时间
            map.put("time",model.getCreateTime());
            map.put("url","http://117.158.204.100:8099/#/dp?id=1&type=11");
            maps.add(map);
        }
        for(PatrolStationRecord model:list2){
            Map map=new HashMap();
            //类别名称
            map.put("name","巡点任务");
            //类型
            map.put("type",2);
            //时间
            map.put("time",model.getLastTime());
            map.put("url","http://117.158.204.100:8099/#/dp?id=1&type=11");
            maps.add(map);
        }
        for(EmergencyReport model:list3){
            Map map=new HashMap();
            //类别名称
            map.put("name","应急事件");
            //类型
            map.put("type",3);
            //时间
            map.put("time",model.getReportTime());
            map.put("url","http://117.158.204.100:8099/#/dp?id=1&type=11");
            maps.add(map);
        }
        for(ValveDeviceHis model:list4){
            Map map=new HashMap();
            //类别名称
            map.put("name","阀井报警");
            //类型
            map.put("type",4);
            //时间
            map.put("time",model.getLastTime());
            map.put("url","http://117.158.204.100:8099/#/dp?id=1&type=11");
            maps.add(map);
        }
        return maps;
    }

    @GetMapping(value = "/getSy")
    public List<Map> getSy(HttpServletRequest request,String devid) throws Exception{
        List<Map> maps=new ArrayList<Map>();
        if(devid.equals("41001")) {
            Map map1 = new HashMap();
            map1.put("name", "上街天伦燃气");
            map1.put("ln", "113.325947");
            map1.put("lt", "34.817374");
            map1.put("address", "郑州市上街区新乡路与金华路交叉口东150米");
            map1.put("url", "http://117.158.204.100:7000/opsli-boot/api/v1/business/file/localimage?id=15");
            map1.put("type", "1");
            maps.add(map1);

            Map map2 = new HashMap();
            map2.put("name", "中心路门站");
            map2.put("ln", "113.278615");
            map2.put("lt", "34.8185");
            map2.put("address", "河南省郑州市上街区中心路南100米");
            map2.put("url", "http://117.158.204.100:7000/opsli-boot/api/v1/business/file/localimage?id=13");
            map2.put("type", "2");
            maps.add(map2);


            Map map3 = new HashMap();
            map3.put("name", "昆仑路加气站");
            map3.put("ln", "113.261365");
            map3.put("lt", "34.81663");
            map3.put("address", "上街区丹江路与昆仑路交叉口");
            map3.put("url", "http://117.158.204.100:7000/opsli-boot/api/v1/business/file/localimage?id=14");
            map3.put("type", "3");
            maps.add(map3);
        } else if(devid.equals("41002")) {
            Map map1 = new HashMap();
            map1.put("name", "浠水中燃城市燃气");
            map1.put("ln", "115.273247");
            map1.put("lt", "30.457739");
            map1.put("address", "黄冈市浠水县新华正街458号");
            map1.put("url", "http://117.158.204.100:7000/opsli-boot/api/v1/business/file/localimage?id=15");
            map1.put("type", "1");
            maps.add(map1);




            Map map3 = new HashMap();
            map3.put("name", "CNG加气站");
            map3.put("ln", "115.253839");
            map3.put("lt", "30.411256");
            map3.put("address", "湖北省黄冈市浠水县S201");
            map3.put("url", "http://117.158.204.100:7000/opsli-boot/api/v1/business/file/localimage?id=14");
            map3.put("type", "3");
            maps.add(map3);
        }



        return maps;
    }

    @GetMapping(value = "/getConfig")
    public Result<Map> getConfig(HttpServletRequest request) throws Exception{
        String username = JwtUtil.getUserNameByToken(request);
        Result<Map> result=new Result<Map>();
        UserModel user = UserUtil.getAppUser(username);
        PatrolConfig config=configService.findOne(user.getCompanyId(),user.getId());
        Integer arate=60;
        Integer rrate=60;
        if(config!=null){
            arate=Integer.valueOf(config.getArate());
            rrate=Integer.valueOf(config.getRrate());

        }else{
            PatrolConfigModel model=new PatrolConfigModel();
            model.setArate("60");
            model.setRrate("60");
            model.setDevid(user.getCompanyId());
            model.setUserId(user.getId());
            configService.insert(model);
        }
        Map map=new HashMap();
        map.put("arate",arate);
        map.put("rrate",rrate);
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }


    @GetMapping(value = "/getDevid")
    public Result<Map> getDevid(HttpServletRequest request) throws Exception{
        String username = JwtUtil.getUserNameByToken(request);
        Result<Map> result=new Result<Map>();
        UserModel user = UserUtil.getAppUser(username);
        Map map=new HashMap();
        map.put("devid",user.getCompanyId());
        result.setResult(map);
        return result;
    }





    /**
     * @功能：获取巡点记录
     * @return
     */
    @GetMapping(value = "/patrolStationRecord")
    public Result<IPage<PatrolStationRecord>> patrolStationRecord(HttpServletRequest request,PatrolStationRecord record,
                                                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        if(user.getIsInspector().equals("1")) {
            record.setUserId(user.getId());
        }
        Result<IPage<PatrolStationRecord>> result = new Result<IPage<PatrolStationRecord>>();
        Page<PatrolStationRecord> pageList = new Page<PatrolStationRecord>(pageNo,pageSize);
        pageList = patrolStationRecordService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：获取应急事件
     * @return
     */
    @GetMapping(value = "/emergencyRecord")
    public Result<IPage<EmergencyReport>> emergencyRecord(HttpServletRequest request, EmergencyReport record,
                                                              @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                              @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,@RequestParam(name="msgCategory", defaultValue="0") String msgCategory) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        if(user.getIsInspector().equals("1")) {
            record.setUserId(user.getId());
        }
        record.setEmergencyState(msgCategory);
        Result<IPage<EmergencyReport>> result = new Result<IPage<EmergencyReport>>();
        Page<EmergencyReport> pageList = new Page<EmergencyReport>(pageNo,pageSize);
        if("1" == record.getEmergencyState() || "1".equals(record.getEmergencyState())){
            record.setEmergencyState("3");
        }
        pageList = emergencyReportService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能： 施工记录app列表
     * @return
     */
    @GetMapping(value = "/emergencyRecordNew")
    public Result<IPage<EmergencyReport>> emergencyRecordNew(HttpServletRequest request, EmergencyReport record,
                                                          @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                          @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        if(user.getIsInspector().equals("1")) {
            record.setUserId(user.getId());
        }
        Result<IPage<EmergencyReport>> result = new Result<IPage<EmergencyReport>>();
        Page<EmergencyReport> pageList = new Page<EmergencyReport>(pageNo,pageSize);
        pageList = emergencyReportService.getMyListNew(pageList, record,(pageNo-1)*pageSize,pageSize);

        List<ProjectRecordModel> modelsList=iProjectRecordService.findList(user.getCompanyId());
        List<EmergencyReport> reportList = pageList.getRecords();

        if(reportList.size() != 0){
            for (EmergencyReport report :reportList){
                if(modelsList.size() != 0){
                    for(ProjectRecordModel model:modelsList){
                        if(null != report.getProjectId() && null != model.getId()){
                            if(report.getProjectId().equals(model.getId())){
                                report.setProjectId(model.getProjectName());
                            }
                        }
                    }
                }
            }
        }

        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能： 项目日志
     * @return
     */
    @GetMapping(value = "/emergencyProjectRecordList")
    public Result<IPage<EmergencyReport>> emergencyProjectRecordList(HttpServletRequest request, EmergencyReport record,
                                                             @RequestParam(name="projectId", defaultValue="") String projectId,
                                                             @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                             @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        record.setProjectId(projectId);
        Result<IPage<EmergencyReport>> result = new Result<IPage<EmergencyReport>>();
        Page<EmergencyReport> pageList = new Page<EmergencyReport>(pageNo,pageSize);
        pageList = emergencyReportService.getMyListNew(pageList, record,(pageNo-1)*pageSize,pageSize);

        List<ProjectRecordModel> modelsList=iProjectRecordService.findList(user.getCompanyId());
        List<EmergencyReport> reportList = pageList.getRecords();

        if(reportList.size() != 0){
            for (EmergencyReport report :reportList){
                if(modelsList.size() != 0){
                    for(ProjectRecordModel model:modelsList){
                        if(null != report.getProjectId() && null != model.getId()){
                            if(report.getProjectId().equals(model.getId())){
                                report.setProjectId(model.getProjectName());
                            }
                        }
                    }
                }
            }
        }

        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：显示该用户下所分配的任务
     * @return
     */
    @GetMapping(value = "/projectTaskList")
    public Result<IPage<ProjectTaskData>> projectTaskList(HttpServletRequest request, ProjectTaskData projectTask,
                                                             @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                             @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        ProjectTaskData projectTaskData=new ProjectTaskData();
        projectTaskData.setDevid(user.getCompanyId());
        if(user.getIsInspector().equals("1")) {
            projectTaskData.setUserNameId(user.getId());
        }

        Result<IPage<ProjectTaskData>> result = new Result<IPage<ProjectTaskData>>();
        Page<ProjectTaskData> pageList = new Page<ProjectTaskData>(pageNo,pageSize);
        pageList = iProjectTaskService.getProjectTaskList(pageList, projectTaskData,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * 显示该任务的进度记录
     * @param id
     * @return
     */
    @GetMapping(value = "/projectTaskRecord")
    public Result<List<ProjectTaskRecord>> projectTaskRecord(HttpServletRequest request,
                                                             @RequestParam(name="id") String id) throws Exception{

        Result<List<ProjectTaskRecord>> result = new Result<List<ProjectTaskRecord>>();

        List<ProjectTaskRecord> list =iProjectTaskRecordService.getFindList(id);


        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    /** 用户更新当前进度
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/taskRecordAdd", method = RequestMethod.PUT)
    @Transactional(readOnly = false)
    public Result<ProjectTaskRecord> taskRecordAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<ProjectTaskRecord> result = new Result<ProjectTaskRecord>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);

            /** 进度上传时间 */
            Date date = new Date();
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String str = format.format(date);

            String taskId=jsonObject.getString("taskId"); //任务id
            String taskName=jsonObject.getString("taskName"); //任务名称
            String taskDescription=jsonObject.getString("taskDescription"); //任务描述
            String advanceProgress=jsonObject.getString("advanceProgress"); //当前进度
            String progressDescription=jsonObject.getString("progressDescription"); //进度描述
            String recordPic=jsonObject.getString("recordPic"); //图片
            String reportVideo=jsonObject.getString("reportVideo"); //视频

            ProjectTaskRecord projectTaskRecord=new ProjectTaskRecord();

            projectTaskRecord.setDevid(user.getCompanyId());
            projectTaskRecord.setTaskId(taskId);
            projectTaskRecord.setTaskName(taskName);
            projectTaskRecord.setTaskDescription(taskDescription);
            projectTaskRecord.setUserId(user.getId());
            projectTaskRecord.setUserName(user.getRealName());
            projectTaskRecord.setAdvanceProgress(advanceProgress);
            projectTaskRecord.setProgressDescription(progressDescription);
            projectTaskRecord.setUploadTime(str);
            projectTaskRecord.setRecordPic(recordPic);
            projectTaskRecord.setReportVideo(reportVideo);
            projectTaskRecordRestController.taskRecordAddController(projectTaskRecord);

            //对任务总进度进行更新
            projectTaskRestController.taskProgressBarUpdate(projectTaskRecord);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * @功能：获取巡点
     * @return
     */
    @GetMapping(value = "/patrolStation")
    public Result<IPage<PatrolStationModel>> patrolStation(HttpServletRequest request, PatrolStationModel record,
                                                          @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                          @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,@RequestParam(name="keyword") String keyword) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        Result<IPage<PatrolStationModel>> result = new Result<IPage<PatrolStationModel>>();
        Page<PatrolStationModel> pageList = new Page<PatrolStationModel>(pageNo,pageSize);
        record.setStationName(keyword);
        pageList = patrolStationService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：获取巡线记录
     * @return
     */
    @GetMapping(value = "/routeRecord")
    public Result<IPage<PatrolRouteRecord>> routeRecord(HttpServletRequest request, PatrolRouteRecord record,
                                                          @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                          @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,@RequestParam(name="msgCategory", defaultValue="0") String msgCategory) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        if(user.getIsInspector().equals("1")) {
            record.setUserId(user.getId());
        }
        record.setState(msgCategory);
        Result<IPage<PatrolRouteRecord>> result = new Result<IPage<PatrolRouteRecord>>();
        Page<PatrolRouteRecord> pageList = new Page<PatrolRouteRecord>(pageNo,pageSize);
        pageList = routeRecordService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：丐版获取轨迹记录
     * @return
     */
    @GetMapping(value = "/routeRecordNew")
    public Result<IPage<PatrolRouteRecord>> routeRecordNew(HttpServletRequest request, PatrolRouteRecord record,
                                                        @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                        @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        if(user.getIsInspector().equals("1")) {
            record.setUserId(user.getId());
        }
        Result<IPage<PatrolRouteRecord>> result = new Result<IPage<PatrolRouteRecord>>();
        Page<PatrolRouteRecord> pageList = new Page<PatrolRouteRecord>(pageNo,pageSize);
        pageList = routeRecordService.getMyListNew(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：获取基准路线
     * @return
     */
    @GetMapping(value = "/routeList")
    public Result<IPage<Route>> routeList(HttpServletRequest request, Route record,
                                          @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                          @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        Result<IPage<Route>> result = new Result<IPage<Route>>();
        Page<Route> pageList = new Page<Route>(pageNo,pageSize);
        pageList = routeService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：获取管道
     * @return
     */
    @GetMapping(value = "/pipelineList")
    public Result<IPage<Pipeline>> pipelineList(HttpServletRequest request, Pipeline record,
                                          @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                          @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        Result<IPage<Pipeline>> result = new Result<IPage<Pipeline>>();
        Page<Pipeline> pageList = new Page<Pipeline>(pageNo,pageSize);
        pageList = iPipelineService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：获取
     * @return
     */
    @GetMapping(value = "/taskPage")
    public Result<IPage<PatrolTask>> taskPage(HttpServletRequest request, PatrolTask record,
                                                          @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                          @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,@RequestParam(name="msgCategory", defaultValue="0")String msgCategory) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        record.setState(msgCategory);
        record.setManager(user.getId());
        Result<IPage<PatrolTask>> result = new Result<IPage<PatrolTask>>();
        Page<PatrolTask> pageList = new Page<PatrolTask>(pageNo,pageSize);
        pageList = taskService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    @GetMapping(value = "/stationTaskPage")
    public Result<IPage<StationTask>> stationTaskPage(HttpServletRequest request, StationTask record,
                                              @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                              @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,@RequestParam(name="msgCategory", defaultValue="0")String msgCategory) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        record.setState(msgCategory);
        record.setManager(user.getId());
        Result<IPage<StationTask>> result = new Result<IPage<StationTask>>();
        Page<StationTask> pageList = new Page<StationTask>(pageNo,pageSize);
        pageList = stationTaskService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }


    /**
     * @功能：获取任务
     * @return
     */
    @GetMapping(value = "/taskList")
    public Result<IPage<PatrolTask>> taskList(HttpServletRequest request, PatrolTask record,
                                              @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                              @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        record.setUserId(user.getId());
        record.setState("0");
        Result<IPage<PatrolTask>> result = new Result<IPage<PatrolTask>>();
        Page<PatrolTask> pageList = new Page<PatrolTask>(pageNo,pageSize);
        pageList = taskService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：获取巡点任务
     * @return
     */
    @GetMapping(value = "/staTaskList")
    public Result<IPage<StationTask>> staTaskList(HttpServletRequest request, StationTask record,
                                              @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                              @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        record.setDevid(user.getCompanyId());
        record.setUserId(user.getId());
        record.setState("0");
        Result<IPage<StationTask>> result = new Result<IPage<StationTask>>();
        Page<StationTask> pageList = new Page<StationTask>(pageNo,pageSize);
        pageList = stationTaskService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：获取隐患任务
     * @return
     */
    @GetMapping(value = "/emergencyTaskList")
    public Result<IPage<EmergencyReportTaskApp>> emergencyTaskList(HttpServletRequest request, EmergencyReportTaskApp record,
                                                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);

        record.setDevid(user.getCompanyId());
        record.setUserId(user.getId());
        record.setEmergencyType("0");

        Result<IPage<EmergencyReportTaskApp>> result = new Result<IPage<EmergencyReportTaskApp>>();
        Page<EmergencyReportTaskApp> pageList = new Page<EmergencyReportTaskApp>(pageNo,pageSize);

        pageList = emergencyReportTaskService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：获取已完成的隐患任务
     * @return
     */
    @GetMapping(value = "/emergencyTaskListFinish")
    public Result<IPage<EmergencyReportTaskApp>> emergencyTaskListFinish(HttpServletRequest request, EmergencyReportTaskApp record,
                                                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) throws Exception{

        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);

        record.setDevid(user.getCompanyId());
        record.setUserId(user.getId());
        record.setEmergencyType("1");

        Result<IPage<EmergencyReportTaskApp>> result = new Result<IPage<EmergencyReportTaskApp>>();
        Page<EmergencyReportTaskApp> pageList = new Page<EmergencyReportTaskApp>(pageNo,pageSize);

        pageList = emergencyReportTaskService.getMyList(pageList, record,(pageNo-1)*pageSize,pageSize);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }

    /**
     * @功能：获取巡点列表
     * @return
     */
    @GetMapping(value = "/patrolStationList")
    public List<Map> patrolStationList(HttpServletRequest request,String ln,String lo) throws Exception{
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        List<PatrolStationModel> models=patrolStationService.findList(user.getCompanyId());
        if(models!=null&&models.size()>0){
            for(PatrolStationModel model:models){
                Map map=new HashMap();
                double d1=new BigDecimal(ln).doubleValue();
                double d2=new BigDecimal(lo).doubleValue();
                double d3=0.0;
                double d4=0.0;
                try {
                    d3=new BigDecimal(model.getLongitude()).doubleValue();
                    d4=new BigDecimal(model.getDimension()).doubleValue();
                }catch (Exception e){
                    System.out.println("ln"+model.getLongitude()+",lo="+model.getDimension());
                }

                double d5=DistanceUtils.getDistance(d1,d2,d3,d4);
                map.put("text",model.getStationName());
                map.put("value",model.getId());
                if(d5<=0.5) {
                    list.add(map);
                }
            }
        }
        return list;
    }

    /**
     * @功能：获取巡点列表  2022/8/30更新的 新增采集点记录 搜索下拉框
     * @return
     */
    @GetMapping(value = "/patrolStationListNew")
    public List<Map> patrolStationListNew(HttpServletRequest request,String ln,String lo) throws Exception{
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        List<PatrolStationModel> models=patrolStationService.findList(user.getCompanyId());
        if(models!=null&&models.size()>0){
            for(PatrolStationModel model:models){
                Map map=new HashMap();
                double d1=new BigDecimal(ln).doubleValue();
                double d2=new BigDecimal(lo).doubleValue();
                double d3=0.0;
                double d4=0.0;
                try {
                    d3=new BigDecimal(model.getLongitude()).doubleValue();
                    d4=new BigDecimal(model.getDimension()).doubleValue();
                }catch (Exception e){
                    System.out.println("ln"+model.getLongitude()+",lo="+model.getDimension());
                }

//                double d5=DistanceUtils.getDistance(d1,d2,d3,d4);
                map.put("name",model.getStationName());
                map.put("id",model.getId());
//                if(d5<=0.5) {
                list.add(map);
//                }
            }
        }
        return list;
    }

    @GetMapping(value = "/projectRecordList")
    public List<Map> projectRecordList(HttpServletRequest request) throws Exception{
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        List<ProjectRecordModel> models=iProjectRecordService.findList(user.getCompanyId());
        if(models!=null&&models.size()>0){
            for(ProjectRecordModel model:models){
                Map map=new HashMap();
                map.put("text",model.getProjectName());
                map.put("value",model.getId());
                list.add(map);
            }
        }
        return list;
    }

    @GetMapping(value = "/findProjectRecord")
    public ProjectRecordModel findProjectRecord(HttpServletRequest request,@RequestParam(name="projectId", defaultValue="") String projectId
                                       ) throws Exception{
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        ProjectRecordModel projectRecordModel=iProjectRecordService.findById(user.getCompanyId(),projectId);

        return  projectRecordModel;
    }

    @GetMapping(value = "/pList")
    public List<Map> pList(HttpServletRequest request) throws Exception{
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        List<PatrolStationModel> models=patrolStationService.findList(user.getCompanyId());
        if(models!=null&&models.size()>0){
            for(PatrolStationModel model:models){
                Map map=new HashMap();
                map.put("ln",model.getLongitude());
                map.put("lo",model.getDimension());
                map.put("ad",model.getStationName());
                list.add(map);

            }
        }
        return list;
    }


    @GetMapping(value = "/dList")
    public List<Map> dList(HttpServletRequest request) throws Exception{
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        Route route=new Route();
        route.setDevid(user.getCompanyId());
        List<Route> models =routeService.getList(route);
        if(models!=null&&models.size()>0){
            for(Route model:models){
                Map map=new HashMap();
                map.put("text",model.getRouteName());
                map.put("value",model.getId());
                list.add(map);
            }
        }
        return list;
    }


    @GetMapping(value = "/dpRoutes")
    public List<Map> dpRoutes(HttpServletRequest request,String devid) throws Exception{
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        Route route=new Route();
        route.setDevid(devid);
        List<Route> models =routeService.getList(route);
        if(models!=null&&models.size()>0){
            for(Route model:models){
                Map map=new HashMap();
                map.put("name",model.getRouteName());
                map.put("id",model.getId());
                List<RouteStation> stations=routeStationService.findList(model.getId());
                if(stations!=null&&stations.size()>0) {
                    for(RouteStation station:stations){
                        MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                        cordinatesVo.setLon(new BigDecimal(station.getLongitude()));
                        cordinatesVo.setLat(new BigDecimal(station.getDimension()));
                        cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                        station.setLongitude(cordinatesVo.getLon().toString());
                        station.setDimension(cordinatesVo.getLat().toString());
                    }
                    map.put("value",stations);
                    map.put("type",1);
                    list.add(map);
                }
            }
        }
        List<PatrolLocationModel> modelss=patrolStationService.findPList(devid);
        if(modelss!=null&&modelss.size()>0){
            for(PatrolLocationModel model:modelss){
                Map map=new HashMap();
                MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
                cordinatesVo.setLat(new BigDecimal(model.getDimension()));
                cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                map.put("ln", cordinatesVo.getLon());
                map.put("lt", cordinatesVo.getLat());
                map.put("userName", model.getUserName());
                map.put("type",2);
                list.add(map);
            }
        }
        return list;
    }

    /**
     * 大屏页面高压管道地图信息
     * @param request
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/dpPipe")
    public List<Map> dpPiPe(HttpServletRequest request,String devid) throws Exception {
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        Pipeline pipeline=new Pipeline();
        pipeline.setDevid(devid);
        pipeline.setPressureType("3");
        List<Pipeline> models =iPipelineService.getList(pipeline);
        if(models!=null&&models.size()>0){
            for(Pipeline model:models){
                Map map=new HashMap();
                map.put("id",model.getId());
                map.put("name",model.getPipelineRoadAme());//管道名称
                map.put("specificationModel",model.getSpecificationModel());//规格型号
                map.put("pipingMaterial",model.getPipingMaterial());//管道材质
                map.put("anticorrosionMaterial",model.getAnticorrosionMaterial());//防腐材质
                map.put("length",model.getLength());//长度
                map.put("operatingPressure",model.getOperatingPressure());//运行压力
                List<PipelineStationDp> stationList=iPipelineStationService.findListDp(model.getId());

                if(stationList!=null&&stationList.size()>0) {

                    PipelineStationDp p1=stationList.get(0);//第一条
                    PipelineStationDp p2=stationList.get(stationList.size()-1);//最后一条.
                    p1.setTheFinal("1");
                    p1.setStarting(model.getOrigin());//起点名称
                    p2.setTheFinal("2");
                    p2.setFinish(model.getDestination());//终点名称

                    for(PipelineStationDp station:stationList){
                        MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                        cordinatesVo.setLon(new BigDecimal(station.getLongitude()));
                        cordinatesVo.setLat(new BigDecimal(station.getDimension()));
                        cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                        station.setLongitude(cordinatesVo.getLon().toString());
                        station.setDimension(cordinatesVo.getLat().toString());
                    }

                    map.put("line",model);
                    map.put("value",stationList);
                    map.put("type",1);
                    list.add(map);
                }
            }
        }
        return list;
    }

    /**
     *大屏页面中压管道地图信息
     * @param request
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/dpPipeMedium")
    public List<Map> dpPipeMedium(HttpServletRequest request,String devid) throws Exception {
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        Pipeline pipeline=new Pipeline();
        pipeline.setDevid(devid);
        pipeline.setPressureType("2");
        List<Pipeline> models =iPipelineService.getList(pipeline);
        if(models!=null&&models.size()>0){
            for(Pipeline model:models){
                Map map=new HashMap();
                map.put("id",model.getId());
                map.put("name",model.getPipelineRoadAme());
                map.put("specificationModel",model.getSpecificationModel());//规格型号
                map.put("pipingMaterial",model.getPipingMaterial());//管道材质
                map.put("anticorrosionMaterial",model.getAnticorrosionMaterial());//防腐材质
                map.put("length",model.getLength());//长度
                map.put("operatingPressure",model.getOperatingPressure());//运行压力
                List<PipelineStationDp> stationList=iPipelineStationService.findListDp(model.getId());

                if(stationList!=null&&stationList.size()>0) {

                    PipelineStationDp p1=stationList.get(0);//第一条
                    PipelineStationDp p2=stationList.get(stationList.size()-1);//最后一条.
                    p1.setTheFinal("1");
                    p1.setStarting(model.getOrigin());//起点名称
                    p2.setTheFinal("2");
                    p2.setFinish(model.getDestination());//终点名称

                    for(PipelineStationDp station:stationList){
                        MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                        cordinatesVo.setLon(new BigDecimal(station.getLongitude()));
                        cordinatesVo.setLat(new BigDecimal(station.getDimension()));
                        cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                        station.setLongitude(cordinatesVo.getLon().toString());
                        station.setDimension(cordinatesVo.getLat().toString());
                    }

                    map.put("line",model);
                    map.put("value",stationList);
                    map.put("type",1);
                    list.add(map);
                }
            }
        }
        return list;
    }

    @GetMapping(value = "/dpRoutesName")
    public List<Map> dpRoutesName(HttpServletRequest request) throws Exception{
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        Route route=new Route();
        route.setDevid("41001");
        List<Route> models =routeService.getList(route);
        if(models!=null&&models.size()>0){
            for(Route model:models){
                Map map=new HashMap();
                map.put("name",model.getRouteName());
                map.put("id",model.getId());
                map.put("type","11");
                list.add(map);
            }
        }
        return list;
    }

    @GetMapping(value = "/dpZStation")
    public List<Map> dpZStation(HttpServletRequest request,String devid) throws Exception{
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        List<PatrolStationModel> models =patrolStationService.findListByType(devid,"1");
        if(models!=null&&models.size()>0){
            for(PatrolStationModel model:models){
                Map map=new HashMap();
                map.put("name",model.getStationName());
                map.put("id",model.getId());
                map.put("type","121");
                MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                if(ZkUtils.isNotBlank(model.getLongitude())) {
                    cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
                    cordinatesVo.setLat(new BigDecimal(model.getDimension()));
                    cordinatesVo = CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                    map.put("ln", cordinatesVo.getLon());
                    map.put("lt", cordinatesVo.getLat());
                    map.put("location", model.getLocation());
                    map.put("userName", model.getUserName());
                    map.put("lastTime", model.getLastTime());
                    map.put("pic", fileUrl+model.getLastPic());
                    map.put("video", fileUrl+model.getLastVideo());
                    list.add(map);
                }
            }
        }
        return list;
    }





    @GetMapping(value = "/dpPeople")
    public List<Map> dpPeople(HttpServletRequest request) throws Exception{
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        List<PatrolLocationModel> models=patrolStationService.findPList("41001");
        if(models!=null&&models.size()>0){
            for(PatrolLocationModel model:models){
                Map map=new HashMap();
                MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
                cordinatesVo.setLat(new BigDecimal(model.getDimension()));
                cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                map.put("ln", cordinatesVo.getLon());
                map.put("lt", cordinatesVo.getLat());
                map.put("userName", model.getUserName());
                list.add(map);
            }
        }
        return list;
    }

    @GetMapping(value = "/tList")
    public List<Map> tList(HttpServletRequest request) throws Exception{
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        List<PatrolStationModel> models =patrolStationService.findList(user.getCompanyId());
        if(models!=null&&models.size()>0){
            for(PatrolStationModel model:models){
                Map map=new HashMap();
                map.put("text",model.getStationName());
                map.put("value",model.getId());
                list.add(map);
            }
        }
        return list;
    }

    @GetMapping(value = "/sList")
    public List<Map> sList(HttpServletRequest request) throws Exception{
        Map datamap=new HashMap();
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        List<PatrolStationModel> models=patrolStationService.findList(user.getCompanyId());
        if(models!=null&&models.size()>0){
            for(PatrolStationModel model:models){
                Map map=new HashMap();
                map.put("text",model.getStationName());
                map.put("value",model.getId());
                list.add(map);
            }
        }
        return list;
    }

    /**
     * @功能：获取管道路线
     * @return
     */
    @GetMapping(value = "/getPipeline")
    public Result<Map> getPipeline(HttpServletRequest request,String routeId) throws Exception{
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        //获取
        List<PipelineStation> routeStations=iPipelineStationService.findList(routeId);
        if(routeStations==null||routeStations.size()==0){
            result.error500("无站点");
            return result;
        }
        //公司为山西安和的坐标转换
        if(user.getCompanyId().equals("41006")){

            for(PipelineStation station:routeStations){
                Map datamap=new HashMap();
                MapCordinatesVo cordinatesVo = new MapCordinatesVo();
                cordinatesVo.setLon(new BigDecimal(station.getLongitude()));
                cordinatesVo.setLat(new BigDecimal(station.getDimension()));
                cordinatesVo = CoordinatesConvertUtil.gd_decrypt(cordinatesVo);
                String longitude = cordinatesVo.getLon().toString();
                String dimension = cordinatesVo.getLat().toString();
                datamap.put("latitude",dimension);
                datamap.put("longitude",longitude);
                list.add(datamap);
            }
            map.put("list",list);
            PipelineStation begin=routeStations.get(0);

            MapCordinatesVo cordinatesVo = new MapCordinatesVo();
            cordinatesVo.setLon(new BigDecimal(begin.getLongitude()));
            cordinatesVo.setLat(new BigDecimal(begin.getDimension()));
            cordinatesVo = CoordinatesConvertUtil.gd_decrypt(cordinatesVo);
            String beginLongitude = cordinatesVo.getLon().toString();
            String beginDimension = cordinatesVo.getLat().toString();
            map.put("bla",beginDimension);
            map.put("blo",beginLongitude);
            PipelineStation end=routeStations.get(routeStations.size()-1);
            MapCordinatesVo cordinatesVo1 = new MapCordinatesVo();
            cordinatesVo1.setLon(new BigDecimal(end.getLongitude()));
            cordinatesVo1.setLat(new BigDecimal(end.getDimension()));
            cordinatesVo1 = CoordinatesConvertUtil.gd_decrypt(cordinatesVo1);
            String endLongitude = cordinatesVo1.getLon().toString();
            String endDimension = cordinatesVo1.getLat().toString();
            map.put("ela",endDimension);
            map.put("elo",endLongitude);

        }else {
            for(PipelineStation station:routeStations){
                Map datamap=new HashMap();
                datamap.put("latitude",station.getDimension());
                datamap.put("longitude",station.getLongitude());
                list.add(datamap);
            }
            map.put("list",list);
            PipelineStation begin=routeStations.get(0);
            PipelineStation end=routeStations.get(routeStations.size()-1);
            map.put("bla",begin.getDimension());
            map.put("blo",begin.getLongitude());
            map.put("ela",end.getDimension());
            map.put("elo",end.getLongitude());
        }
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }


    @Autowired
    RouteStationServiceImpl rs;

    /**
     * @功能：获取基准路线
     * @return
     */
    @GetMapping(value = "/getRoute")
    public Result<Map> getRoute(HttpServletRequest request,String routeId) throws Exception{
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        if(!user.getCompanyId().equals("41006")){
            //获取
            List<RouteStation> routeStations=routeStationService.findList(routeId);
            if(routeStations==null||routeStations.size()==0){
                result.error500("无站点");
                return result;
            }
            for(RouteStation station:routeStations){
                Map datamap=new HashMap();
                datamap.put("latitude",station.getDimension());
                datamap.put("longitude",station.getLongitude());
                list.add(datamap);
            }
            map.put("list",list);
            RouteStation begin=routeStations.get(0);
            RouteStation end=routeStations.get(routeStations.size()-1);
            map.put("bla",begin.getDimension());
            map.put("blo",begin.getLongitude());
            map.put("ela",end.getDimension());
            map.put("elo",end.getLongitude());
            map.put("type",1);
        }else{
            if(routeId.equals("1528987038416699393") || routeId.equals("1506506467359559682")){
                List mlist=new ArrayList();
                List l2 = new ArrayList();
                List<RouteStation> l = rs.findAnZeList(routeId);
                for (int i = 0; i < l.size(); i++) {
                    Map m = new HashMap();
                    RouteStation r = l.get(i);
                    String longitude1 = r.getLongitude();
                    String dimension1 = r.getDimension();
                    String longitude=null;
                    String dimension=null;
                    if (longitude1.equals("0") && dimension1.equals("0")) {
                        longitude="0";
                        dimension="0";
                        m.put("longitude", 0);//经度
                        m.put("latitude", 0);//维度
                    }else {
                        MapCordinatesVo cordinatesVo = new MapCordinatesVo();
                        cordinatesVo.setLon(new BigDecimal(r.getLongitude()));
                        cordinatesVo.setLat(new BigDecimal(r.getDimension()));
                        cordinatesVo = CoordinatesConvertUtil.gd_decrypt(cordinatesVo);
                        longitude = cordinatesVo.getLon().toString();
                        dimension = cordinatesVo.getLat().toString();
                        m.put("longitude", longitude);//经度
                        m.put("latitude", dimension);//维度
                    }

                    l2.add(m);
                    if (longitude.equals("0") && dimension.equals("0")) {
                        List l3 = new ArrayList();
                        for (int a = 0; a < l2.size() - 1; a++) {
                            l3.add(l2.get(a));
                        }
                        mlist.add(l3);
                        l2.clear();
                    }
                }
                map.put("type",2);
                map.put("kind",1); //1为安和公司0分隔符组装的基准路线
                map.put("list",mlist);
            }else {
                //获取
                List<RouteStation> routeStations=routeStationService.findList(routeId);
                if(routeStations==null||routeStations.size()==0){
                    result.error500("无站点");
                    return result;
                }
                for(RouteStation station:routeStations){
                    Map datamap=new HashMap();
                    MapCordinatesVo cordinatesVo = new MapCordinatesVo();
                    cordinatesVo.setLon(new BigDecimal(station.getLongitude()));
                    cordinatesVo.setLat(new BigDecimal(station.getDimension()));
                    cordinatesVo = CoordinatesConvertUtil.gd_decrypt(cordinatesVo);
                    String longitude = cordinatesVo.getLon().toString();
                    String dimension = cordinatesVo.getLat().toString();
                    datamap.put("latitude",dimension);
                    datamap.put("longitude",longitude);
                    list.add(datamap);
                }
                map.put("type",2);
                map.put("kind",2); //2为安和公司不是拼装的基础路线
                map.put("list",list);
            }

        }

        // 缓存Key
        String cacheKey = PREFIX_ROUTEID_PATH + routeId;

        redisTemplate.opsForValue().set(cacheKey, map);

        result.setSuccess(true);
        result.setResult(map);
        return result;
    }

    /**
     * @功能：获取巡线路线
     * @return
     */
    @GetMapping(value = "/getRouteXx")
    public Result<Map> getRouteXx(HttpServletRequest request,String id) throws Exception{
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        //ln经度,lo纬度
        PatrolRouteRecordModel routeRecord=routeRecordService.get(id);
        //轨迹
        String trail=routeRecord.getTrail();
        List<Map> list=new ArrayList<Map>();
        List<Map> mapList=new ArrayList<Map>();
        //修改轨迹
        if(ZkUtils.isNotBlank(trail)){
            mapList = JSON.parseArray(trail, Map.class);
        }else{
            //修改任务开始时间
            result.error500("暂无轨迹");
            return result;
        }
        for(Map m:mapList){
            Map datamap=new HashMap();
            datamap.put("latitude",m.get("ln"));
            datamap.put("longitude",m.get("lt"));
            list.add(datamap);
        }
        result.setSuccess(true);
        map.put("list",list);
        map.put("bla",list.get(0).get("longitude"));
        map.put("blo",list.get(0).get("latitude"));
        map.put("zla",list.get(list.size()-1).get("longitude"));
        map.put("zlo",list.get(list.size()-1).get("latitude"));
        result.setResult(map);
        return result;
    }

    /**
     * 根据高德经纬度获取详细信息
     * @param lng
     * @param lat
     * @return
     * @throws IOException
     */
    public  String getCoordinate(String lng, String lat) throws IOException {
        //在高德地图上申请的key值
        //https://console.amap.com/dev/key/app
        String key = "418c2a17a0da7fa1b3f7c38fcd9d04b8";

        StringBuilder resultData = new StringBuilder();
        StringBuilder https = new StringBuilder("http://restapi.amap.com/v3/geocode/regeo?key=");
        //经纬度地址
        StringBuilder localhost = new StringBuilder("&location="+lng+","+lat);
        StringBuilder httpsTail = new StringBuilder("&poitype=&radius=&extensions=base&batch=true");
        String url = https.append(key).append(localhost).append(httpsTail).toString();
        URL myURL = null;
        URLConnection httpsConn = null;
        try {
            myURL = new URL(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        InputStreamReader insr = null;
        BufferedReader br = null;
        try {
            httpsConn = myURL.openConnection();// 不使用代理
            if (httpsConn != null) {
                insr = new InputStreamReader(httpsConn.getInputStream(), "UTF-8");
                br = new BufferedReader(insr);
                String data = null;
                while ((data = br.readLine()) != null) {
                    resultData.append(data);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (insr != null) {
                insr.close();
            }
            if (br != null) {
                br.close();
            }
        }
        if (resultData.toString().indexOf("regeocodes") == 0) {
            return null;
        }

        JSONObject jsonObject = JSONObject.parseObject(resultData.toString());
        String str = jsonObject.getString("regeocodes");
        JSONArray jsonArray = JSONArray.fromObject(str);
        String s=jsonArray.getString(0);
        JSONObject jo = JSONObject.parseObject(s);
        String address = jo.getString("formatted_address");
        return address;
    }

    /**
     * @功能：获取最新路线
     * @return
     */
    @GetMapping(value = "/getNewRouteIos")
    @Transactional(readOnly = false)
    public Result<Map> ggetNewRouteIos(HttpServletRequest request,String ln,String lo,String id) throws Exception{

        String address= this.getCoordinate(ln,lo);
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        //ln经度,lo纬度
        PatrolTaskModel taskModel=taskService.get(id);
        PatrolRouteRecordModel recordModel=new PatrolRouteRecordModel();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        PatrolRouteRecord routeRecord=routeRecordService.getOne(taskModel.getSign());
        //轨迹
        String trail=routeRecord.getTrail();
        List<Map> list=new ArrayList<Map>();
        List<Map> mapList=new ArrayList<Map>();
        Map newMap=new HashMap();
        //修改轨迹
        if(ZkUtils.isNotBlank(trail)){
            mapList = JSON.parseArray(trail, Map.class);
            Map smap=new HashMap();
            for(Map m:mapList){
                String key=m.get("ln").toString()+m.get("lt")+m.get("lo");
                smap.put(key,key);
            }
            String newkey=lo+ln+address;
            if(smap.get(newkey)==null&&mapList.size()<10000){
                newMap.put("lt",ln);
                newMap.put("ln",lo);
                newMap.put("lo",address);
                newMap.put("tm",ZkUtils.getM());
                mapList.add(newMap);
            }
        }else{
            //修改任务开始时间
            taskModel.setBeginTime(ZkUtils.getDateStr());
            taskService.update(taskModel);
            recordModel.setBeginTime(ZkUtils.getDateStr());
            newMap.put("lt",ln);
            newMap.put("ln",lo);
            newMap.put("lo",address);
            newMap.put("tm",ZkUtils.getM());
            mapList.add(newMap);
        }




        //新轨迹
        trail=JSON.toJSONString(mapList);
        for(Map m:mapList){
            Map datamap=new HashMap();
            datamap.put("latitude",m.get("ln"));
            datamap.put("longitude",m.get("lt"));
            list.add(datamap);
        }
        //修改巡线记录
        recordModel.setId(routeRecord.getId());
        recordModel.setTrail(trail);
        recordModel.setLastTime(ZkUtils.getDateStr());
        routeRecordService.update(recordModel);
        //修改人员位置
        PatrolLocationModel locationModel=locationService.findOne(user.getId());
        if(locationModel==null){
            //新增
            locationModel=new PatrolLocationModel();
            locationModel.setDevid(user.getCompanyId());
            locationModel.setDevname(user.getCompany());
            locationModel.setUserId(user.getId());
            locationModel.setUserName(user.getRealName());
            locationModel.setLastTime(ZkUtils.getDateStr());
            locationModel.setLocation(address);
            locationModel.setLongitude(ln);
            locationModel.setDimension(lo);
            locationService.insert(locationModel);
        }else{
            locationModel.setLastTime(ZkUtils.getDateStr());
            locationModel.setLocation(address);
            locationModel.setLongitude(ln);
            locationModel.setDimension(lo);
            locationService.update(locationModel);

        }
        result.setSuccess(true);
        map.put("list",list);
        map.put("bla",list.get(0).get("longitude"));
        map.put("blo",list.get(0).get("latitude"));
        result.setResult(map);
        return result;
    }


    /**
     * @功能：获取最新任务
     * @return
     */
    @GetMapping(value = "/getTaskNew")
    public Map getTaskNew(HttpServletRequest request) throws Exception{

        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        PatrolTask patrolTask=new PatrolTask();
        patrolTask.setUserId(user.getId());
        List<PatrolTask> list= patrolTaskMapper.getTodayListNew(patrolTask);
        String routeId="";
        String id="";
        List<Date> dates =new ArrayList();
        for (PatrolTask pt :list){
            dates.add(pt.getCreateTime());
        }
        Date maxDate = Collections.max(dates);
        for (PatrolTask pts:list){
            Integer da=maxDate.compareTo(pts.getCreateTime());
            if(da==0){
                routeId=pts.getRouteId();
                id=pts.getId();
            }
        }
        Map map=new HashMap();

        map.put("id",id);
        map.put("routeId",routeId);

        return map;
    }

    /**
     * @功能：获取最新路线
     * @return
     */
    @GetMapping(value = "/getNewRoute")
    @Transactional(readOnly = false)
    public Result<Map> ggetNewRoute(HttpServletRequest request,String ln,String lo,String address,String id,String routeId) throws Exception{
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        //ln经度,lo纬度  根据去巡检任务表查出路线标识
        PatrolTaskModel taskModel=taskService.get(id);
        PatrolRouteRecordModel recordModel=new PatrolRouteRecordModel();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        //根据路线标识 去巡线记录表里查当前线路的所有轨迹
        PatrolRouteRecord routeRecord=routeRecordService.getOne(taskModel.getSign());
        //轨迹
        String trail=routeRecord.getTrail();
        List<Map> list=new ArrayList<Map>();
        List<Map> mapList=new ArrayList<Map>();
        //山西安和位置纠偏
//        if(user.getCompanyId().equals("41006")){
//            Map rectifyMap=getLocationRectify(ln,lo,id,routeId);
//            ln = rectifyMap.get("ln").toString();
//            lo = rectifyMap.get("lo").toString();
//        }
        Map newMap=new HashMap();
        //修改轨迹  如果没有轨迹 那就是刚开始执行任务，  如果有轨迹把数据返回到前端展示
        if(ZkUtils.isNotBlank(trail)){
            mapList = JSON.parseArray(trail, Map.class);
            Map smap=new HashMap();
            for(Map m:mapList){
                String key=m.get("ln").toString()+m.get("lt")+m.get("lo");
               smap.put(key,key);
            }
            String newkey=lo+ln+address;
            if(smap.get(newkey)==null&&mapList.size()<10000){
                newMap.put("lt",ln);
                newMap.put("ln",lo);
                newMap.put("lo",address);
                newMap.put("tm",ZkUtils.getM());
                mapList.add(newMap);
            }
        }else{
            //修改任务开始时间
            taskModel.setBeginTime(ZkUtils.getDateStr());
            taskService.update(taskModel);
            recordModel.setBeginTime(ZkUtils.getDateStr());
            newMap.put("lt",ln);
            newMap.put("ln",lo);
            newMap.put("lo",address);
            newMap.put("tm",ZkUtils.getM());
            mapList.add(newMap);
        }

        //新轨迹  把新轨迹追加到了老轨迹上
        trail=JSON.toJSONString(mapList);
        //把新轨迹组装成前端需要的数据
        for(Map m:mapList){
            Map datamap=new HashMap();
//            String lan= (String) m.get("ln");
//            String lat= (String) m.get("lt");
//            MapCordinatesVo cordinatesVo=new MapCordinatesVo();
//            cordinatesVo.setLon(new BigDecimal(lan));
//            cordinatesVo.setLat(new BigDecimal(lat));
//            cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
//            datamap.put("latitude", cordinatesVo.getLon());
//            datamap.put("longitude",cordinatesVo.getLat());
            datamap.put("latitude",m.get("ln"));
            datamap.put("longitude",m.get("lt"));
            list.add(datamap);
        }
        //修改巡线记录
        recordModel.setId(routeRecord.getId());
        recordModel.setTrail(trail);
        recordModel.setLastTime(ZkUtils.getDateStr());
        routeRecordService.update(recordModel);
        //修改人员位置
        PatrolLocationModel locationModel=locationService.findOne(user.getId());
        if(locationModel==null){
            //新增
            locationModel=new PatrolLocationModel();
            locationModel.setDevid(user.getCompanyId());
            locationModel.setDevname(user.getCompany());
            locationModel.setUserId(user.getId());
            locationModel.setUserName(user.getRealName());
            locationModel.setLastTime(ZkUtils.getDateStr());
            locationModel.setLocation(address);
            locationModel.setLongitude(ln);
            locationModel.setDimension(lo);
            locationService.insert(locationModel);
        }else{
            locationModel.setLastTime(ZkUtils.getDateStr());
            locationModel.setLocation(address);
            locationModel.setLongitude(ln);
            locationModel.setDimension(lo);
            locationService.update(locationModel);

        }
        result.setSuccess(true);
        map.put("list",list);
        map.put("bla",list.get(0).get("longitude"));
        map.put("blo",list.get(0).get("latitude"));
        result.setResult(map);
        return result;
    }

    /**
     * @功能：获取最新路线
     * @return
     */
    @GetMapping(value = "/getNewRouteProjectIos")
    @Transactional(readOnly = false)
    public Result<Map> getNewRouteProjectIos(HttpServletRequest request,String ln,String lo,String id,String routeId) throws Exception{
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        String address= this.getCoordinate(ln,lo);

        //ln经度,lo纬度  根据去巡检任务表查出路线标识
        PatrolTaskModel taskModel=taskService.get(id);
        PatrolRouteRecordModel recordModel=new PatrolRouteRecordModel();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        //根据路线标识 去巡线记录表里查当前线路的所有轨迹
        PatrolRouteRecord routeRecord=routeRecordService.getOne(taskModel.getSign());
        //轨迹
        String trail=routeRecord.getTrail();
        List<Map> list=new ArrayList<Map>();
        List<Map> mapList=new ArrayList<Map>();
        //山西安和位置纠偏
//        if(user.getCompanyId().equals("41006")){
//            Map rectifyMap=getLocationRectify(ln,lo,id,routeId);
//            ln = rectifyMap.get("ln").toString();
//            lo = rectifyMap.get("lo").toString();
//        }
        Map newMap=new HashMap();
        //修改轨迹  如果没有轨迹 那就是刚开始执行任务，  如果有轨迹把数据返回到前端展示
        if(ZkUtils.isNotBlank(trail)){
            mapList = JSON.parseArray(trail, Map.class);
            Map smap=new HashMap();
            for(Map m:mapList){
                String key=m.get("ln").toString()+m.get("lt")+m.get("lo");
                smap.put(key,key);
            }
            String newkey=lo+ln+address;
            if(smap.get(newkey)==null&&mapList.size()<10000){
                newMap.put("lt",ln);
                newMap.put("ln",lo);
                newMap.put("lo",address);
                newMap.put("tm",ZkUtils.getM());
                mapList.add(newMap);
            }
        }else{
            //修改任务开始时间
            taskModel.setBeginTime(ZkUtils.getDateStr());
            taskService.update(taskModel);
            recordModel.setBeginTime(ZkUtils.getDateStr());
            newMap.put("lt",ln);
            newMap.put("ln",lo);
            newMap.put("lo",address);
            newMap.put("tm",ZkUtils.getM());
            mapList.add(newMap);
        }
        //新轨迹  把新轨迹追加到了老轨迹上
        trail=JSON.toJSONString(mapList);
        //把新轨迹组装成前端需要的数据
        for(Map m:mapList){
            Map datamap=new HashMap();
//            String lan= (String) m.get("ln");
//            String lat= (String) m.get("lt");
//            MapCordinatesVo cordinatesVo=new MapCordinatesVo();
//            cordinatesVo.setLon(new BigDecimal(lan));
//            cordinatesVo.setLat(new BigDecimal(lat));
//            cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
//            datamap.put("latitude", cordinatesVo.getLon());
//            datamap.put("longitude",cordinatesVo.getLat());
            datamap.put("latitude",m.get("ln"));
            datamap.put("longitude",m.get("lt"));
            list.add(datamap);
        }
        //修改巡线记录
        recordModel.setId(routeRecord.getId());
        recordModel.setTrail(trail);
        recordModel.setLastTime(ZkUtils.getDateStr());
        routeRecordService.update(recordModel);
        //修改人员位置
        PatrolLocationModel locationModel=locationService.findOne(user.getId());
        if(locationModel==null){
            //新增
            locationModel=new PatrolLocationModel();
            locationModel.setDevid(user.getCompanyId());
            locationModel.setDevname(user.getCompany());
            locationModel.setUserId(user.getId());
            locationModel.setUserName(user.getRealName());
            locationModel.setLastTime(ZkUtils.getDateStr());
            locationModel.setLocation(address);
            locationModel.setLongitude(ln);
            locationModel.setDimension(lo);
            locationService.insert(locationModel);
        }else{
            locationModel.setLastTime(ZkUtils.getDateStr());
            locationModel.setLocation(address);
            locationModel.setLongitude(ln);
            locationModel.setDimension(lo);
            locationService.update(locationModel);
        }
        result.setSuccess(true);
        map.put("list",list);
        map.put("bla",list.get(0).get("longitude"));
        map.put("blo",list.get(0).get("latitude"));
        result.setResult(map);
        return result;
    }

    /**
     * @功能：ios app 根据经纬度 解析成详细信息
     * @return
     */
    @GetMapping(value = "/getAddressIos")
    @Transactional(readOnly = false)
    public Result<String> getAddressIos(HttpServletRequest request,String ln,String lo) throws Exception{
        Result<String> result=new Result<String>();

        String address= this.getCoordinate(ln,lo);

        result.setSuccess(true);
        result.setResult(address);
        return result;
    }

    @SneakyThrows
    public Map getLocationRectify(String lon, String lat, String id, String routeId){

        // 缓存Key
        String cacheKey = PREFIX_ROUTEID_PATH + routeId;

        // 先从缓存里拿
        Object obj =redisTemplate.opsForValue().get(cacheKey);

        Map<String, Object> beanMap = Convert.toMap(String.class, Object.class, obj);

        String kind=beanMap.get("kind").toString();
        Object routeList=beanMap.get("list");//转list

        List toLists=Convert.toList(routeList);
        //用来存放所有基准路线id
        List<RouteStationAPP> routeStationAPPList=new ArrayList<>();
        //1为安和公司0分隔符组装的基准路线
        if(kind.equals("1")){

            for (int i=0;i<toLists.size();i++){
                Object objt = toLists.get(i);
                List objectList=Convert.toList(objt);

                for (int j=0;j<objectList.size();j++){
                    Object staion = objectList.get(j);
                    List<RouteStationAPP> routeStationList=Convert.toList(RouteStationAPP.class,staion);
                    RouteStationAPP routeStationAPP= routeStationList.get(0);
                    routeStationAPPList.add(routeStationAPP);
                }
            }
        } else {
            for (int i=0;i<toLists.size();i++){
                Object staion = toLists.get(i);
                List<RouteStationAPP> routeStationList=Convert.toList(RouteStationAPP.class,staion);
                RouteStationAPP routeStationAPP= routeStationList.get(0);
                routeStationAPPList.add(routeStationAPP);
            }
        }
        Map mapArrly=new HashMap<>();
        double[] arr = new double[routeStationAPPList.size()];
        Integer i=0;
        for (RouteStationAPP app:routeStationAPPList){
            Double nowLng=app.getLongitude();
            Double nowLat=app.getLatitude();
            Double dlon=Double.valueOf(lon);
            Double dlat=Double.valueOf(lat);

            // console.log('基准路线的的纬度：' + nowLng+','+nowLat);
            //计算两个经纬度之间的直线距离  最近的
            Double EARTH_RADIUS = 6378.137;
            Double radLat1 = dlat * Math.PI / 180.0;
            Double radLat2 = nowLat * Math.PI / 180.0;
            Double a = radLat1 - radLat2;
            Double b = (dlon * Math.PI / 180.0) - (nowLng * Math.PI / 180.0);
            Double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
                    + Math.cos(radLat1) * Math.cos(radLat2)
                    * Math.pow(Math.sin(b / 2), 2)));
            s = s * EARTH_RADIUS;

            arr[i]=s;

            Map mapsd=new HashMap<>();

            Double jsLon = nowLng;
            Double jsLat = nowLat;
            mapsd.put("jsLon",jsLon);//经度
            mapsd.put("jsLat", jsLat);//纬度
            mapArrly.put(s,mapsd);
            i++;
        }

        //取第一个数组自动排序的 最近距离
        Arrays.sort(arr);
        Double a = arr[0];

        Object jparr = mapArrly.get(a);

        List<RouteStationZJ> routeStationZJS=Convert.toList(RouteStationZJ.class,jparr);
        RouteStationZJ routeStationZJ=routeStationZJS.get(0);
        Double zjlon = routeStationZJ.getJsLon();
        Double zjlat = routeStationZJ.getJsLat();
        System.out.println("当前经纬度"+lon+","+lat);
        System.out.println("最近的经纬度"+zjlon+","+zjlat+"距离"+a);

        //如果小于两百米 返回最近基准路线上的点
        if(a < 0.02){
            lon=zjlon.toString();
            lat=zjlat.toString();
        }

        Map map=new HashMap<>();
        map.put("ln",lon);
        map.put("lo",lat);
        return map;
    }



    /**
     * @功能：自动设置管道
     * @return
     */
        @GetMapping(value = "/setPipeline")
    public Result<Map> setPipeline(HttpServletRequest request,String ln,String lo,String address,String id) throws Exception{
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        List<Map> list=new ArrayList<Map>();
        //获取
        List<PipelineStation> routeStations=iPipelineStationService.findList(id);
        PipelineStationModel stationModel=new PipelineStationModel();
        stationModel.setRouteid(id);
        stationModel.setDimension(lo);
        stationModel.setLongitude(ln);
        stationModel.setLocation(address);
        boolean sign=false;
        if(routeStations==null||routeStations.size()==0){
            routeStations=new ArrayList<PipelineStation>();
           stationModel.setSort("1");
           sign=true;
        }else {
            Map smap=new HashMap();
            for(PipelineStation station:routeStations){
                String key=station.getLongitude()+station.getDimension()+station.getLocation();
                smap.put(key,key);
            }
            String newkey=ln+lo+address;
            PipelineStation end=routeStations.get(routeStations.size()-1);
            Integer a=Integer.valueOf(end.getSort())+1;
            stationModel.setSort(String.valueOf(a));
            if(smap.get(newkey)==null&&routeStations.size()<10000){
                sign=true;
            }
        }
        if(sign){
            iPipelineStationService.insert(stationModel);
        }

        PipelineStation s=new PipelineStation();
        s.setDimension(lo);
        s.setLongitude(ln);
        if(sign) {
            routeStations.add(s);
        }
        for( PipelineStation station:routeStations){
            Map datamap=new HashMap();
            datamap.put("latitude",station.getDimension());
            datamap.put("longitude",station.getLongitude());
            list.add(datamap);
        }
        map.put("list",list);
        map.put("ln",ln);
        map.put("lo",lo);
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }

    /**
     * @功能：自动设置管道
     * @return
     */
    @GetMapping(value = "/setRoute")
    public Result<Map> setRoute(HttpServletRequest request,String ln,String lo,String address,String id) throws Exception{
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        List<Map> list=new ArrayList<Map>();
        //获取
        List<RouteStation> routeStations=routeStationService.findList(id);
        RouteStationModel stationModel=new RouteStationModel();
        stationModel.setRouteid(id);
        stationModel.setDimension(lo);
        stationModel.setLongitude(ln);
        stationModel.setLocation(address);
        boolean sign=false;
        if(routeStations==null||routeStations.size()==0){
            routeStations=new ArrayList<RouteStation>();
            stationModel.setSort("1");
            sign=true;
        }else {
            Map smap=new HashMap();
            for(RouteStation station:routeStations){
                String key=station.getLongitude()+station.getDimension()+station.getLocation();
                smap.put(key,key);
            }
            String newkey=ln+lo+address;
            RouteStation end=routeStations.get(routeStations.size()-1);
            Integer a=Integer.valueOf(end.getSort())+1;
            stationModel.setSort(String.valueOf(a));
            if(smap.get(newkey)==null&&routeStations.size()<10000){
                sign=true;
            }
        }
        if(sign){
            routeStationService.insert(stationModel);
        }
        RouteStation s=new RouteStation();
        s.setDimension(lo);
        s.setLongitude(ln);
        if(sign) {
            routeStations.add(s);
        }
        for(RouteStation station:routeStations){
            Map datamap=new HashMap();
            datamap.put("latitude",station.getDimension());
            datamap.put("longitude",station.getLongitude());
            list.add(datamap);
        }
        map.put("list",list);
        map.put("ln",ln);
        map.put("lo",lo);
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }

    /**
     * @功能：获取管道最新地图
     * @return
     */
    @GetMapping(value = "/setPipelineNew")
    public Result<Map> setPipelineNew(HttpServletRequest request,String id) throws Exception{
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        List<Map> list=new ArrayList<Map>();
        //获取
        List<PipelineStation> routeStations=iPipelineStationService.findList(id);
        if(routeStations==null||routeStations.size()==0){
            result.error500("暂无轨迹");
            return result;
        }
        for(PipelineStation station:routeStations){
            Map datamap=new HashMap();
            datamap.put("latitude",station.getDimension());
            datamap.put("longitude",station.getLongitude());
            list.add(datamap);
        }
        PipelineStation end=routeStations.get(routeStations.size()-1);
        map.put("list",list);
        map.put("ln",end.getLongitude());
        map.put("lo",end.getDimension());
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }

    /**
     * @功能：获取最新地图
     * @return
     */
    @GetMapping(value = "/setRouteNew")
    public Result<Map> setRouteNew(HttpServletRequest request,String id) throws Exception{
        Result<Map> result=new Result<Map>();
        Map map=new HashMap();
        List<Map> list=new ArrayList<Map>();
        //获取
        List<RouteStation> routeStations=routeStationService.findList(id);
        if(routeStations==null||routeStations.size()==0){
            result.error500("暂无轨迹");
            return result;
        }
        for(RouteStation station:routeStations){
            Map datamap=new HashMap();
            datamap.put("latitude",station.getDimension());
            datamap.put("longitude",station.getLongitude());
            list.add(datamap);
        }
        RouteStation end=routeStations.get(routeStations.size()-1);
        map.put("list",list);
        map.put("ln",end.getLongitude());
        map.put("lo",end.getDimension());
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }

    @GetMapping(value = "/getStalocation")
    public Map getStalocation(HttpServletRequest request,String stationId) throws Exception{
        PatrolStationModel model=patrolStationService.get(stationId);
        Map map=new HashMap();
        map.put("ln",model.getLongitude());
        map.put("lo",model.getDimension());
        map.put("name",model.getStationName());
        map.put("ad",model.getLocation());
        map.put("villageName",model.getVillageName() );
        map.put("type",model.getType());
        return map;
    }

    @GetMapping(value = "/getNavigation")
    public Map getNavigation(HttpServletRequest request,String stationId) throws Exception{
        PatrolStationModel model=patrolStationService.get(stationId);
        //        WGS84转高德火星坐标系
        double[] gpsCoUtils= GpsCoordinateUtils.calGCJ02toWGS84(Double.parseDouble(model.getDimension()),Double.parseDouble(model.getLongitude()));
        Double n = gpsCoUtils[0];//经度
        Double l = gpsCoUtils[1];//维度
        Map map=new HashMap();
        map.put("mkln",l); //转成大地坐标系的坐标 供导航使用
        map.put("mklo",n);
        map.put("ln",model.getLongitude());
        map.put("lo",model.getDimension());
        map.put("name",model.getStationName());
        map.put("ad",model.getLocation());
        map.put("villageName",model.getVillageName() );
        map.put("type",model.getType());


        return map;
    }

    /**
     * 查看隐患位置
     * @param request
     * @param stationId
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/getEmergencyLocation")
    public Map getEmergencyLocation(HttpServletRequest request,String stationId) throws Exception{
        EmergencyReport  report=reportMapper.findById(stationId);

        Map map=new HashMap();
        map.put("ln",report.getLongitude());
        map.put("lo",report.getDimension());
        map.put("name",report.getEmergencyTitle());
        map.put("ad",report.getLocation());
        return map;
    }

    /**
     * @功能：获取今日巡点任务
     * @return
     */
    @GetMapping(value = "/getTodayStation")
    public Map getTodayStation(HttpServletRequest request) throws Exception{
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        //修改之前巡点前任务为已完成
        /*stationTaskService.updateOne(user.getId());*/
        //查询今日任务(数量)
        StationTask task=new StationTask();
        task.setDevid(user.getCompanyId());
        task.setUserId(user.getId());
        List<StationTask> todays=stationTaskService.getTodayList(task);
        Map map=new HashMap();
        if(todays==null||todays.size()==0){
            //自动生成新任务
            List<StationTaskModel> batch=new ArrayList<StationTaskModel>();
            List<UserStation> stations=userStationService.getMyList(user.getId());
            if(stations!=null&&stations.size()>0){
                for(UserStation station:stations){
                    StationTaskModel model=new StationTaskModel();
                    model.setDevid(user.getCompanyId());
                    model.setDevname(user.getCompany());
                    model.setUserId(user.getId());
                    model.setUserName(user.getRealName());
                    model.setStationId(station.getStationId());
                    model.setStationName(station.getStationName());
                    model.setType("0");
                    model.setState("0");
                    model.setBeginTime(ZkUtils.getDateStr());
                    batch.add(model);
                }
                //批量插入
                stationTaskService.insertBatch(batch);
                //未完成
                map.put("tcount",batch.size());
                //已完成
                map.put("tcountEnd","0");

            }else{
                //未完成
                map.put("tcount","0");
                //已完成
                map.put("tcountEnd","0");
            }
        }else{
            //当前已经有任务,获取数量
            //未完成
            List<StationTask> begins = todays.stream().filter(s->s.getState().equals("0")).collect(Collectors.toList());
            //已完成
            List<StationTask> ends = todays.stream().filter(s->s.getState().equals("1")).collect(Collectors.toList());
            if(begins==null||begins.size()==0){
                map.put("tcount",0);
            }else{
                map.put("tcount",begins.size());
            }
            if(ends==null||ends.size()==0){
                map.put("tcountEnd",0);
            }else{
                map.put("tcountEnd",ends.size());
            }
        }
        return map;
    }

    /**
     * @功能：获取今日巡点任务
     * @return
     */
    @GetMapping(value = "/getEmergencyTask")
    public Map getEmergencyTask(HttpServletRequest request) throws Exception{

        Map map=new HashMap();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);//获取用户id

        List<EmergencyReportTask> zero =taskMapper.findListUserIdZero(user.getId());
        List<EmergencyReportTask> one =taskMapper.findListUserIdOne(user.getId());
        //未完成
        map.put("tcount",zero.size());
        //已完成
        map.put("tcountEnd",one.size());
        return map;
    }

    /**
     * @功能：获取今日任务
     * @return
     */
    @GetMapping(value = "/getToday")
    public Map getToday(HttpServletRequest request) throws Exception{
        List<Map> list=new ArrayList<Map>();
        String userName = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(userName);
        PatrolStationRecord stationRecord=new PatrolStationRecord();
        stationRecord.setUserId(user.getId());
        stationRecord.setDevid(user.getCompanyId());
        //今日巡点记录
        List<PatrolStationRecord> stationRecords=patrolStationRecordService.getTodayList(stationRecord);
        PatrolRouteRecord routeRecord=new PatrolRouteRecord();
        routeRecord.setDevid(user.getCompanyId());
        routeRecord.setUserId(user.getId());
        List<PatrolRouteRecord> lists=routeRecordService.getTodayList(routeRecord);
        routeRecord.setState("0");
        //今日进行中巡线记录
        List<PatrolRouteRecord> routeRecords=routeRecordService.getTodayList(routeRecord);
        routeRecord.setState("1");
        //今日完成巡线记录
        List<PatrolRouteRecord> routeRecordsEnd=routeRecordService.getTodayList(routeRecord);
        PatrolTask task=new PatrolTask();
        task.setDevid(user.getCompanyId());
        task.setUserId(user.getId());
        task.setState("0");
        //今日进行中巡线任务
        List<PatrolTask> tasks=taskService.getTodayList(task);
        task.setState("1");
        //今日已完成巡线任务
        List<PatrolTask> tasksEnd=taskService.getTodayList(task);
        Map map=new HashMap();
        if(stationRecords!=null) {
            map.put("scount", stationRecords.size());
        }else{
            map.put("scount", 0);
        }
        if(routeRecords!=null){
            map.put("rcount", routeRecords.size());
        }else{
            map.put("rcount", 0);
        }
        if(routeRecordsEnd!=null){
            map.put("rcountEnd", routeRecordsEnd.size());
        }else{
            map.put("rcountEnd", routeRecordsEnd.size());
        }
        if(tasks!=null){
            map.put("tcount", tasks.size());
        }else{
            map.put("tcount", tasks.size());
        }
        if(tasksEnd!=null){
            map.put("tcountEnd", tasksEnd.size());
        }else{
            map.put("tcountEnd", tasksEnd.size());
        }
        if(lists!=null&&lists.size()>0){
            map.put("startTime", lists.get(0).getBeginTime());
        }else{
            map.put("startTime", "暂未开始");
        }
        return map;
    }

    @GetMapping(value = "/getSignRecord")
    public Map getSignRecord(HttpServletRequest request) {
        List<Map> list=new ArrayList<Map>();
        String userName ="";
        try {
            userName = JwtUtil.getUserNameByToken(request);
        }catch (Exception e){
            System.out.println(e);
        }
        UserModel user = UserUtil.getAppUser(userName);
       /* List<PatrolStationModel> models=patrolStationService.findList(user.getCompanyId());
        if(models!=null&&models.size()>0){
            for(PatrolStationModel model:models){
                Map map=new HashMap();
                map.put("text",model.getStationName());
                map.put("value",model.getId());
                list.add(map);
            }
        }*/
        SignRecord record=signRecordService.findL(user.getId());
        Integer count=signRecordService.findcount(user.getId());
        Map map=new HashMap();
        if(record!=null) {
            map.put("signTime", record.getSignTime());
        }else{
            map.put("signTime", "暂无");
        }
        map.put("signCount",count);
        return map;
    }

    @RequestMapping(value = "/getPic", method = RequestMethod.GET)
    public List<Map> getPic(HttpServletRequest request,@RequestParam("pic")String pic) throws Exception{
        String username = JwtUtil.getUserNameByToken(request);
        System.out.println(username);
        List<Map> list=new ArrayList<Map>();
        if(ZkUtils.isNotBlank(pic)){
            String[] arr=pic.split(",");
            for(int i=0;i<arr.length;i++){
                Map map=new HashMap();
                map.put("id",i+1);
                map.put("src",fileUrl+arr[i]);
                list.add(map);
            }
        }
        return list;
    }

    @RequestMapping(value = "/getVideo", method = RequestMethod.GET)
    public String getVideo(HttpServletRequest request,@RequestParam("pic")String pic) throws Exception{
        if(ZkUtils.isNotBlank(pic)){
            pic=fileUrl+pic;
        }
        return pic;
    }

    @RequestMapping(value = "/getUser", method = RequestMethod.GET)
    public Map getUser(HttpServletRequest request) throws Exception{
        String username = JwtUtil.getUserNameByToken(request);
        UserModel user = UserUtil.getAppUser(username);
        Map map=new HashMap();
        map.put("userName",user.getRealName());
        map.put("devname",user.getCompany());
        return map;
    }



    /**
     * 完成巡检
     * @return
     */
    @RequestMapping(value = "/patrolEnd", method = RequestMethod.GET)
    public Result<Map> patrolEnd(HttpServletRequest request, String id) {
        Result<Map> result = new Result<Map>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);

            PatrolTaskModel taskModel=new PatrolTaskModel();
            taskModel=taskService.get(id);
            taskModel.setEndTime(ZkUtils.getDateStr());
            taskModel.setState("1");
            taskService.update(taskModel);
            PatrolRouteRecord routeRecord=routeRecordService.getOne(taskModel.getSign());
            PatrolRouteRecordModel recordModel=new PatrolRouteRecordModel();
            recordModel.setLastTime(ZkUtils.getDateStr());
            recordModel.setId(routeRecord.getId());
            recordModel.setEndTime(ZkUtils.getDateStr());
            recordModel.setState("1");
            routeRecordService.update(recordModel);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }


    @RequestMapping(value = "/setConfig", method = RequestMethod.PUT)
    @Transactional(readOnly = false)
    public Result<Map> setConfig(HttpServletRequest request, @RequestBody JSONObject jsonObject) throws Exception {
        String username = JwtUtil.getUserNameByToken(request);
        Result<Map> result = new Result<Map>();
        UserModel user = UserUtil.getAppUser(username);
        String arate=jsonObject.getString("arate");
        String rrate=jsonObject.getString("rrate");
        configService.updateOne(user.getCompanyId(),user.getId(),arate,rrate);
        Map map = new HashMap();
        map.put("arate", arate);
        map.put("rrate", rrate);
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }

    /**
     * 修改巡点
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/updateStation", method = RequestMethod.PUT)
    @Transactional(readOnly = false)
    public Result<Map> updateStation(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<Map> result = new Result<Map>();
        String id=jsonObject.getString("id");
        String location=jsonObject.getString("location");
        String longitude=jsonObject.getString("longitude");
        String dimension=jsonObject.getString("dimension");
        PatrolStationModel model=new PatrolStationModel();
        model.setId(id);
        model.setLocation(location);
        model.setDimension(dimension);
        model.setLongitude(longitude);
       patrolStationService.update(model);
        result.setSuccess(true);
        return result;

    }


    /**
     * 新增巡点记录
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/patrolStationAdd", method = RequestMethod.PUT)
    @Transactional(readOnly = false)
    public Result<PatrolStationRecordModel> patrolStationAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<PatrolStationRecordModel> result = new Result<PatrolStationRecordModel>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            String stationId=jsonObject.getString("stationId");
            String description=jsonObject.getString("description");
            String recordPic=jsonObject.getString("recordPic");
            String recordVideo=jsonObject.getString("recordVideo");
            Integer leakageCondition=jsonObject.getInteger("leakageCondition");
            Integer hygieneCondition=jsonObject.getInteger("hygieneCondition");
            Integer sinkCondition=jsonObject.getInteger("sinkCondition");
            Integer damageCondition=jsonObject.getInteger("damageCondition");
            Integer occupyCondition=jsonObject.getInteger("occupyCondition");
            Integer buryCondition=jsonObject.getInteger("buryCondition");

            PatrolStationModel stationModel=patrolStationService.get(stationId);
            PatrolStationRecordModel model=new PatrolStationRecordModel();
            model.setStationName(stationModel.getStationName());
            model.setStationId(stationId);
            model.setDescription(description);
            model.setLocation(stationModel.getLocation());
            model.setLongitude(stationModel.getLongitude());
            model.setDimension(stationModel.getDimension());
            model.setRecordPic(recordPic);
            model.setRecordVideo(recordVideo);
            model.setLastTime(ZkUtils.getDateStr());
            model.setDevid(user.getCompanyId());
            model.setDevname(user.getCompany());
            model.setUserId(user.getId());
            model.setUserName(user.getRealName());
            model.setLeakageCondition(leakageCondition);
            model.setHygieneCondition(hygieneCondition);
            model.setSinkCondition(sinkCondition);
            model.setDamageCondition(damageCondition);
            model.setOccupyCondition(occupyCondition);
            model.setBuryCondition(buryCondition);
            model.setStationType(stationModel.getType());
            model.setState("1");
            StationTask task=new StationTask();
            task.setUserId(user.getId());
            task.setDevid(user.getCompanyId());
            task.setState("0");
            task.setStationId(stationId);
            List<StationTask> tasks=stationTaskService.getList(task);
            if(tasks!=null&&tasks.size()>0){
                String sign=ZkUtils.getRandomStr();
                for(StationTask stationTask:tasks){
                    stationTaskService.updateTask(sign,stationTask.getId(),"1");
                }
                model.setSign(sign);
            }
            patrolStationRecordService.insert(model);
            stationModel.setLastTime(ZkUtils.getDateStr());
            stationModel.setLastPic(recordPic);
            stationModel.setLastVideo(recordVideo);
            stationModel.setUserName(user.getRealName());
            stationModel.setLastDescription(description);
            stationModel.setLastState("1");
            patrolStationService.update(stationModel);

            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 隐患维修人员提交
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/emergencyAddTask", method = RequestMethod.PUT)
    @Transactional(readOnly = false)
    public Result<EmergencyReportTaskApp> emergencyAddTask(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<EmergencyReportTaskApp> result = new Result<EmergencyReportTaskApp>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);

            String id=jsonObject.getString("id"); //隐患任务表id
            String stationId=jsonObject.getString("stationId");//隐患id
            String recordPic=jsonObject.getString("recordPic");//维修图片
            String recordVideo=jsonObject.getString("recordVideo");//维修视频
            String defectCause=jsonObject.getString("defectCause");//隐患原因
            String defectResult=jsonObject.getString("defectResult");//隐患结果
            /** 任务完成时间 */
            Date date = new Date();
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String str = format.format(date);

            EmergencyReportTaskApp reportTaskApp=new EmergencyReportTaskApp();

            reportTaskApp.setId(id);
//            reportTaskApp.setDevid(user.getCompanyId());
            reportTaskApp.setEndTime(str);
            reportTaskApp.setEmergencyType("1");//已结束
            reportTaskApp.setRecordPic(recordPic);//维修图片
            reportTaskApp.setRecordVideo(recordVideo);//维修视频
            reportTaskApp.setDefectCause(defectCause);//隐患原因
            reportTaskApp.setDefectResult(defectResult);//隐患结果
            //往任务表更新数据
            emergencyReportTaskMapper.updateByPrimaryKeySelective(reportTaskApp);
            //更新隐患表状态
            reportMapper.updateStateTwo(stationId);

            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 新增巡点记录
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/stationAdd", method = RequestMethod.PUT)
    public Result<PatrolStationModel> stationAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<PatrolStationModel> result = new Result<PatrolStationModel>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            String stationName=jsonObject.getString("stationName");
            String description=jsonObject.getString("description");
            String location=jsonObject.getString("location");
            String longitude=jsonObject.getString("longitude");
            String dimension=jsonObject.getString("dimension");
            String type=jsonObject.getString("type");
            //新增巡点时 如果字符串为空 则为默认的主阀门井
            if(type.equals("")){
                type="1";
            }
            String villageName=jsonObject.getString("villageName");

            PatrolStationModel model=new PatrolStationModel();
            model.setStationName(stationName);
            model.setDescription(description);
            model.setLocation(location);
            model.setLongitude(longitude);
            model.setDimension(dimension);
            model.setType(type);
            model.setVillageName(villageName);
            model.setDevid(user.getCompanyId());
            model.setDevname(user.getCompany());
            patrolStationService.insert(model);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 新增应急事件
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/emergencyAdd", method = RequestMethod.PUT)
    public Result<EmergencyReportModel> emergencyAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<EmergencyReportModel> result = new Result<EmergencyReportModel>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            String emergencyTitle=jsonObject.getString("emergencyTitle");
            String description=jsonObject.getString("description");
            String reportPic=jsonObject.getString("reportPic");
            String reportVideo=jsonObject.getString("reportVideo");
            String location=jsonObject.getString("location");
            String longitude=jsonObject.getString("longitude");
            String dimension=jsonObject.getString("dimension");
            EmergencyReportModel model=new EmergencyReportModel();
            model.setEmergencyTitle(emergencyTitle);
            model.setDescription(description);
            model.setLocation(location);
            model.setLongitude(longitude);
            model.setDimension(dimension);
            model.setReportPic(reportPic);
            model.setReportVideo(reportVideo);
            model.setReportTime(ZkUtils.getDateStr());
            model.setDevid(user.getCompanyId());
            model.setDevname(user.getCompany());
            model.setUserId(user.getId());
            model.setUserName(user.getRealName());
            emergencyReportService.insert(model);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 新增施工记录
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/buildAdd", method = RequestMethod.PUT)
    public Result<EmergencyReportModel> buildAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<EmergencyReportModel> result = new Result<EmergencyReportModel>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            String emergencyTitle=jsonObject.getString("emergencyTitle");
            String description=jsonObject.getString("description");
            String reportPic=jsonObject.getString("reportPic");
            String reportVideo=jsonObject.getString("reportVideo");
            String location=jsonObject.getString("location");
            String longitude=jsonObject.getString("longitude");
            String dimension=jsonObject.getString("dimension");
            String reportTime=jsonObject.getString("reportTime");
            String time=jsonObject.getString("time");
            String projectId=jsonObject.getString("projectId");
            String installedNumber=jsonObject.getString("installedNumber");

            if(null != time){
                if(time.length() <= 5){
                    time+=":00";
                }
                reportTime+=" ";
                reportTime+=time;
            }
            if(null != reportTime){
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = simpleDateFormat.parse(reportTime);
                reportTime = simpleDateFormat.format(date);
            }

            EmergencyReportModel model=new EmergencyReportModel();
            model.setEmergencyTitle(emergencyTitle);
            model.setDescription(description);
            model.setLocation(location);
            model.setLongitude(longitude);
            model.setDimension(dimension);
            model.setReportPic(reportPic);
            model.setReportVideo(reportVideo);
            if(null != reportTime){
                model.setReportTime(reportTime);
            }else {
                model.setReportTime(ZkUtils.getDateStr());
            }
            model.setDevid(user.getCompanyId());
            model.setDevname(user.getCompany());
            model.setUserId(user.getId());
            model.setUserName(user.getRealName());
            if(null != projectId){
                model.setProjectId(projectId);
            }
            model.setInstalledNumber(Integer.valueOf(installedNumber));
            emergencyReportService.insert(model);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 新增基准点
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/routeStationAdd", method = RequestMethod.PUT)
    public Result<RouteStationModel> routeStationAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<RouteStationModel> result = new Result<RouteStationModel>();
        try {
            String routeId=jsonObject.getString("routeid");
            String location=jsonObject.getString("location");
            String longitude=jsonObject.getString("longitude");
            String dimension=jsonObject.getString("dimension");
            RouteStationModel model=new RouteStationModel();

            model.setLocation(location);
            model.setLongitude(longitude);
            model.setDimension(dimension);
            model.setRouteid(routeId);
            //获取
            List<RouteStation> routeStations=routeStationService.findList(routeId);
            if(routeStations==null||routeStations.size()==0){
                model.setSort("1");
            }else {
                RouteStation end=routeStations.get(routeStations.size()-1);
                Integer a=Integer.valueOf(end.getSort())+1;
                model.setSort(String.valueOf(a));
            }
            routeStationService.insert(model);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 新增基准点 1
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/pipelineStationAdd", method = RequestMethod.PUT)
    public Result<PipelineStationModel> pipelineStationAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<PipelineStationModel> result = new Result<PipelineStationModel>();
        try {
            String routeId=jsonObject.getString("routeid");
            String location=jsonObject.getString("location");
            String longitude=jsonObject.getString("longitude");
            String dimension=jsonObject.getString("dimension");
            PipelineStationModel model=new PipelineStationModel();

            model.setLocation(location);
            model.setLongitude(longitude);
            model.setDimension(dimension);
            model.setRouteid(routeId);
            //获取
            List<PipelineStation> routeStations=iPipelineStationService.findList(routeId);
            if(routeStations==null||routeStations.size()==0){
                model.setSort("1");
            }else {
                PipelineStation end=routeStations.get(routeStations.size()-1);
                Integer a=Integer.valueOf(end.getSort())+1;
                model.setSort(String.valueOf(a));
            }
            iPipelineStationService.insert(model);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }


    /**
     * 新增巡检
     * @return
     */
    @RequestMapping(value = "/patrolAdd", method = RequestMethod.PUT)
    @Transactional(readOnly = false)
    public Result<Map> patrolAdd(HttpServletRequest request) {
        Result<Map> result = new Result<Map>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            if(user==null){
                result.error500("获取用户失败!");
                return result;
            }
            //把之前任务改为完成
            routeRecordService.updateOne(user.getId());
            taskService.updateOne(user.getId());
            //查询今日有没有巡检任务
            PatrolTask task=new PatrolTask();
            task.setUserId(user.getId());
            task.setDevid(user.getCompanyId());
            List<PatrolTask> patrolTasks=taskService.getTodayList(task);

            List<PatrolTask> patrolTasks1=taskService.getTodayListOne(task);//取今天任务最新的一条
            //41006公司每天 可自动下发多个任务
            if(user.getCompanyId().equals("41006") || user.getCompanyId()=="41006"){

                if(patrolTasks!=null && patrolTasks.size()>0){

                    //判断任务表 只要没有正在进行中的任务系统就自动下发
                    boolean falg=true;
                    for (PatrolTask patrolTask1 :patrolTasks1){
                        if(patrolTask1.getState().equals("0") || patrolTask1.getState()=="0"){
                            falg=false;
                            break;
                        }
                    }
                    //判断最新任务是否结束 0未结束不用下发
                    if(!falg){
                        result.setSuccess(true);
                        return result;
                    } else {
                        //无任务,需要创建
                        //获取当前用户路线
                        List<UserRoute> routes = userRouteService.getMyList(user.getId());
                        if (routes == null || routes.size() == 0) {
                            result.setSuccess(true);
                            return result;
                        }
                        for (UserRoute route : routes) {
                            String sign = ZkUtils.getRandomStr();
                            //创建任务
                            PatrolTaskModel taskModel = new PatrolTaskModel();
                            taskModel.setDevid(user.getCompanyId());
                            taskModel.setDevname(user.getCompany());
                            taskModel.setUserId(user.getId());
                            taskModel.setUserName(user.getRealName());
                            taskModel.setRouteId(route.getRouteId());
                            taskModel.setRouteName(route.getRouteName());
                            taskModel.setSign(sign);
                            taskModel.setType("0");
                            taskModel.setState("0");
                            taskModel.setManager(user.getId());
                            taskService.insert(taskModel);
                            //创建巡线线路
                            PatrolRouteRecordModel recordModel=new PatrolRouteRecordModel();
                            recordModel.setDevid(user.getCompanyId());
                            recordModel.setDevname(user.getCompany());
                            recordModel.setUserId(user.getId());
                            recordModel.setUserName(user.getRealName());
                            recordModel.setRouteId(route.getRouteId());
                            recordModel.setRouteName(route.getRouteName());
                            recordModel.setSign(sign);
                            recordModel.setType("0");
                            recordModel.setState("0");
                            routeRecordService.insert(recordModel);
                        }
                    }

                }else {
                    //无任务,需要创建
                    //获取当前用户路线
                    List<UserRoute> routes = userRouteService.getMyList(user.getId());
                    if (routes == null || routes.size() == 0) {
                        result.setSuccess(true);
                        return result;
                    }
                    for (UserRoute route : routes) {
                        String sign = ZkUtils.getRandomStr();
                        //创建任务
                        PatrolTaskModel taskModel = new PatrolTaskModel();
                        taskModel.setDevid(user.getCompanyId());
                        taskModel.setDevname(user.getCompany());
                        taskModel.setUserId(user.getId());
                        taskModel.setUserName(user.getRealName());
                        taskModel.setRouteId(route.getRouteId());
                        taskModel.setRouteName(route.getRouteName());
                        taskModel.setSign(sign);
                        taskModel.setType("0");
                        taskModel.setState("0");
                        taskModel.setManager(user.getId());
                        taskService.insert(taskModel);
                        //创建巡线线路
                        PatrolRouteRecordModel recordModel=new PatrolRouteRecordModel();
                        recordModel.setDevid(user.getCompanyId());
                        recordModel.setDevname(user.getCompany());
                        recordModel.setUserId(user.getId());
                        recordModel.setUserName(user.getRealName());
                        recordModel.setRouteId(route.getRouteId());
                        recordModel.setRouteName(route.getRouteName());
                        recordModel.setSign(sign);
                        recordModel.setType("0");
                        recordModel.setState("0");
                        routeRecordService.insert(recordModel);
                    }
                }

            }else {
                if(patrolTasks!=null&&patrolTasks.size()>0){
                    result.setSuccess(true);
                    return result;
                }else {
                    //无任务,需要创建
                    //获取当前用户路线
                    List<UserRoute> routes = userRouteService.getMyList(user.getId());
                    if (routes == null || routes.size() == 0) {
                        result.setSuccess(true);
                        return result;
                    }
                    for (UserRoute route : routes) {
                        String sign = ZkUtils.getRandomStr();
                        //创建任务
                        PatrolTaskModel taskModel = new PatrolTaskModel();
                        taskModel.setDevid(user.getCompanyId());
                        taskModel.setDevname(user.getCompany());
                        taskModel.setUserId(user.getId());
                        taskModel.setUserName(user.getRealName());
                        taskModel.setRouteId(route.getRouteId());
                        taskModel.setRouteName(route.getRouteName());
                        taskModel.setSign(sign);
                        taskModel.setType("0");
                        taskModel.setState("0");
                        taskModel.setManager(user.getId());
                        taskService.insert(taskModel);
                        //创建巡线线路
                        PatrolRouteRecordModel recordModel=new PatrolRouteRecordModel();
                        recordModel.setDevid(user.getCompanyId());
                        recordModel.setDevname(user.getCompany());
                        recordModel.setUserId(user.getId());
                        recordModel.setUserName(user.getRealName());
                        recordModel.setRouteId(route.getRouteId());
                        recordModel.setRouteName(route.getRouteName());
                        recordModel.setSign(sign);
                        recordModel.setType("0");
                        recordModel.setState("0");
                        routeRecordService.insert(recordModel);
                    }
                }
            }

            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }


    /**
     * 新增巡检
     * @return
     */
    @RequestMapping(value = "/taskAdd", method = RequestMethod.PUT)
    @Transactional(readOnly = false)
    public Result<Map> taskAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<Map> result = new Result<Map>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            if(user==null){
                result.error500("获取用户失败!");
                return result;
            }
            String routeId=jsonObject.getString("routeId");
            String userId=jsonObject.getString("userId");
            String description=jsonObject.getString("description");
            RouteModel model=routeService.get(routeId);
            String sign = ZkUtils.getRandomStr();
            //创建任务
            PatrolTaskModel taskModel = new PatrolTaskModel();
            taskModel.setDevid(user.getCompanyId());
            taskModel.setDevname(user.getCompany());
            taskModel.setUserId(userId);
            taskModel.setUserName(UserUtil.getUserName(userId));
            taskModel.setRouteId(routeId);
            taskModel.setRouteName(model.getRouteName());
            taskModel.setSign(sign);
            taskModel.setType("0");
            taskModel.setState("0");
            taskModel.setManager(user.getId());
            taskModel.setDescription(description);
            taskService.insert(taskModel);
            //创建巡线线路
            PatrolRouteRecordModel recordModel=new PatrolRouteRecordModel();
            recordModel.setDevid(user.getCompanyId());
            recordModel.setDevname(user.getCompany());
            recordModel.setUserId(userId);
            recordModel.setUserName(UserUtil.getUserName(userId));
            recordModel.setRouteId(routeId);
            recordModel.setRouteName(model.getRouteName());
            recordModel.setSign(sign);
            recordModel.setType("0");
            recordModel.setState("0");
            routeRecordService.insert(recordModel);



            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }


    @RequestMapping(value = "/taskAddSta", method = RequestMethod.PUT)
    @Transactional(readOnly = false)
    public Result<Map> taskAddSta(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<Map> result = new Result<Map>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            if(user==null){
                result.error500("获取用户失败!");
                return result;
            }
            String stationId=jsonObject.getString("stationId");
            String userId=jsonObject.getString("userId");
            String description=jsonObject.getString("description");
            PatrolStationModel model=patrolStationService.get(stationId);
            //创建任务
            StationTaskModel taskModel = new StationTaskModel();
            taskModel.setDevid(user.getCompanyId());
            taskModel.setDevname(user.getCompany());
            taskModel.setUserId(userId);
            taskModel.setUserName(UserUtil.getUserName(userId));
            taskModel.setStationId(stationId);
            taskModel.setStationName(model.getStationName());
            taskModel.setType("0");
            taskModel.setState("0");
            taskModel.setManager(user.getId());
            taskModel.setDescription(description);
            taskModel.setBeginTime(ZkUtils.getDateStr());
            taskModel.setStationType(model.getType());
            stationTaskService.insert(taskModel);



            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 新增签到记录
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/signAdd", method = RequestMethod.PUT)
    public Result<SignRecordModel> signAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<SignRecordModel> result = new Result<SignRecordModel>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            String location=jsonObject.getString("location");
            if(null == location || location.equals("")){
                result.setSuccess(false);
                result.setMessage("地理位置不能为空！");
            }else {
                SignRecordModel model=new SignRecordModel();
                model.setSignTime(ZkUtils.getDateStr());
                model.setDevid(user.getCompanyId());
                model.setDevname(user.getCompany());
                model.setUserid(user.getId());
                model.setUsername(user.getRealName());
                model.setSignLocation(location);
                signRecordService.insert(model);
                result.setSuccess(true);
                result.setMessage(model.getSignTime());
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 新增基准路线
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/routeAdd", method = RequestMethod.PUT)
    public Result<RouteModel> routeAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<RouteModel> result = new Result<RouteModel>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            String routeName=jsonObject.getString("routeName");
            String routeDescrib=jsonObject.getString("routeDescrib");
            RouteModel model=new RouteModel();
            model.setDevid(user.getCompanyId());
            model.setDevname(user.getCompany());
            model.setRouteDescrib(routeDescrib);
            model.setRouteName(routeName);
            model.setUserName(user.getRealName());
            routeService.insert(model);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 新增管道
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/pipelineAdd", method = RequestMethod.PUT)
    public Result<PipelineModel> pipelineAdd(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        Result<PipelineModel> result = new Result<PipelineModel>();
        try {
            String username = JwtUtil.getUserNameByToken(request);
            UserModel user = UserUtil.getAppUser(username);
            //管道名称
            String pipelineRoadAme=jsonObject.getString("pipelineRoadAme");
            //起点
            String origin=jsonObject.getString("origin");
            //终点
            String destination=jsonObject.getString("destination");
            //压力种类
            String pressureType=jsonObject.getString("pressureType");
            //规格型号
            String specificationModel=jsonObject.getString("specificationModel");
            //管道材质
            String pipingMaterial=jsonObject.getString("pipingMaterial");
            //防腐材质
            String anticorrosionMaterial=jsonObject.getString("anticorrosionMaterial");
            //长度
            String length=jsonObject.getString("length");
            //运行压力
            String operatingPressure=jsonObject.getString("operatingPressure");
            PipelineModel model=new PipelineModel();
            model.setDevid(user.getCompanyId());
            model.setDevname(user.getCompany());
            model.setPipelineRoadAme(pipelineRoadAme);
            model.setOrigin(origin);
            model.setDestination(destination);
            model.setPressureType(pressureType);
            model.setSpecificationModel(specificationModel);
            model.setPipingMaterial(pipingMaterial);
            model.setAnticorrosionMaterial(anticorrosionMaterial);
            model.setLength(length);
            model.setOperatingPressure(operatingPressure);
            model.setUserName(user.getRealName());
            iPipelineService.insert(model);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败!");
        }
        return result;
    }

    /**
     * 文件上传统一方法
     * @param request
     * @param response
     * @return
     */
    @PostMapping(value = "/upload")
    public Result<?> upload(HttpServletRequest request, HttpServletResponse response) {
        Result<?> result = new Result<>();
        String savePath = "";
        String bizPath = request.getParameter("biz");
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象

        String ctxPath = filePath;
        bizPath=ZkUtils.getDateStrType();


        String s=ImageCompress.thumbnail(file,ctxPath,bizPath);
        System.out.println(s);
        if(s!=null){
            FileManageModel model=new FileManageModel();
            model.setDocpath(ctxPath);
            model.setFilepath(s);
            String fileid=ZkUtils.getRandomStr();
            model.setFileid(fileid);
            fileManageService.insert(model);
            String path="/business/file/localimage?id="+fileid;
            result.setMessage(path);
            result.setSuccess(true);
        }else {
            result.setMessage("上传失败！");
            result.setSuccess(false);
        }
         /*   savePath = this.uploadLocal(file,bizPath);
        String ctxPath = filePath;
        if(savePath!=null){
            FileManageModel model=new FileManageModel();
            model.setDocpath(ctxPath);
            model.setFilepath(savePath);
            String fileid=ZkUtils.getRandomStr();
            model.setFileid(fileid);
            fileManageService.insert(model);
            String path="/business/file/localimage?id="+fileid;
            result.setMessage(path);
            result.setSuccess(true);
        }else {
            result.setMessage("上传失败！");
            result.setSuccess(false);
        }*/
        System.out.println(savePath);
        return result;
    }

    /**
     * 文件上传统一方法
     * @param request
     * @param response
     * @return
     */
    @PostMapping(value = "/uploadVideo")
    public Result<?> uploadVideo(HttpServletRequest request, HttpServletResponse response) {
        Result<?> result = new Result<>();
        String savePath = "";
        String bizPath = request.getParameter("biz");
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
        savePath = this.uploadLocal(file,bizPath);
        String ctxPath = filePath;
        if(savePath!=null){
            FileManageModel model=new FileManageModel();
            model.setDocpath(ctxPath);
            model.setFilepath(savePath);
            String fileid=ZkUtils.getRandomStr();
            model.setFileid(fileid);
            fileManageService.insert(model);
            String path="/business/file/localvideo?id="+fileid;
            result.setMessage(path);
            result.setSuccess(true);
        }else {
            result.setMessage("上传失败！");
            result.setSuccess(false);
        }
        System.out.println(savePath);
        return result;
    }


    /**
     * 本地文件上传
     * @param mf 文件
     * @param bizPath  自定义路径
     * @return
     */
    private String uploadLocal(MultipartFile mf,String bizPath){
        try {
            String ctxPath = filePath;
            bizPath=ZkUtils.getDateStrType();
            String fileName = null;
            File file = new File(ctxPath + File.separator + bizPath + File.separator );
            if (!file.exists()) {
                file.mkdirs();// 创建文件根目录
            }
            String orgName = mf.getOriginalFilename();// 获取文件名
            orgName = getFileName(orgName);
            if(orgName.indexOf(".")!=-1){
                fileName = ZkUtils.getRandomStr() + orgName.substring(orgName.lastIndexOf("."));
            }else{
                fileName = orgName+ "_" + System.currentTimeMillis();
            }
            String savePath = file.getPath() + File.separator + fileName;
            File savefile = new File(savePath);
            FileCopyUtils.copy(mf.getBytes(), savefile);
            String dbpath = null;
            if(bizPath!=null){
                dbpath = bizPath + File.separator + fileName;
            }else{
                dbpath = fileName;
            }
            if (dbpath.contains("\\")) {
                dbpath = dbpath.replace("\\", "/");
            }
            return dbpath;
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        return "";
    }


    /**
     * 判断文件名是否带盘符，重新处理
     * @param fileName
     * @return
     */
    public static String getFileName(String fileName){
        //判断是否带有盘符信息
        // Check for Unix-style path
        int unixSep = fileName.lastIndexOf('/');
        // Check for Windows-style path
        int winSep = fileName.lastIndexOf('\\');
        // Cut off at latest possible point
        int pos = (winSep > unixSep ? winSep : unixSep);
        if (pos != -1)  {
            // Any sort of path separator found...
            fileName = fileName.substring(pos + 1);
        }
        //替换上传文件名字的特殊字符
        fileName = fileName.replace("=","").replace(",","").replace("&","")
                .replace("#", "").replace("“", "").replace("”", "");
        //替换上传文件名字中的空格
        fileName=fileName.replaceAll("\\s","");
        return fileName;
    }








}
